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

Function main

example/thread_pool.cpp:40–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38 }
39}
40int main(int , char * [])
41{
42 const std::size_t n = 4u;
43 boost::asio::thread_pool tp{n};
44
45 // a very simple thread pool
46
47 auto cpl =
48 [](std::exception_ptr ep)
49 {
50 if (ep)
51 try
52 {
53 std::rethrow_exception(ep);
54 }
55 catch(std::exception & e)
56 {
57 printf("Completed with exception %s\n", e.what());
58 }
59 };
60
61 cobalt::spawn(boost::asio::make_strand(tp.get_executor()), work(0, 10, 32), cpl);
62 cobalt::spawn(boost::asio::make_strand(tp.get_executor()), work(10, 20, 22), cpl);
63 cobalt::spawn(boost::asio::make_strand(tp.get_executor()), work(50, 60, -18), cpl);
64
65 // wait them so they don't leak.
66 tp.join();
67 return 0;
68}

Callers

nothing calls this directly

Calls 5

spawnFunction · 0.85
whatMethod · 0.80
joinMethod · 0.80
workFunction · 0.70
get_executorMethod · 0.45

Tested by

no test coverage detected