MCPcopy Create free account
hub / github.com/boostorg/cobalt / co_main

Function co_main

example/thread.cpp:68–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68cobalt::main co_main(int argc, char *argv [])
69{
70 // a very simple thread pool
71 std::vector<cobalt::thread> thrs;
72 const std::size_t n = 4u;
73
74 request_channel rc{co_await cobalt::this_coro::executor};
75 for (auto i = 0u; i < n; i++)
76 thrs.push_back(worker(rc));
77
78 try
79 {
80 // this is an over simplification, but emulated multiple pieces of
81 // code in the single threaded environment offloading work to the thread.
82 co_await cobalt::join(
83 work(rc, 0, 10, 32),
84 work(rc, 10, 20, 22),
85 work(rc, 50, 60, -18)
86 );
87
88 }
89 catch(std::exception & e)
90 {
91 printf("Completed with exception %s\n", e.what());
92 }
93 // closing the channel will cause the threads to complete
94 rc.close();
95 // wait them so they don't leak.
96 co_await cobalt::join(thrs);
97 co_return 0;
98}

Callers

nothing calls this directly

Calls 6

workerFunction · 0.85
joinFunction · 0.85
push_backMethod · 0.80
whatMethod · 0.80
workFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected