Commit e694fce03aa5d9ea3327f1c9dcdfb223e414973e
1 parent
2242157f
Updated mutithreaded example
Showing
1 changed file
with
6 additions
and
2 deletions
12-threads.cpp
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | int a = 0; |
9 | 9 | |
10 | 10 | void WorkerThread(asio::io_context& io_context, int counter) { |
11 | - std::cout << counter << ".\n"; | |
11 | + std::cout << counter << "\n"; | |
12 | 12 | io_context.run(); |
13 | 13 | std::cout << "End.\n"; |
14 | 14 | } |
... | ... | @@ -25,7 +25,11 @@ int main(void) { |
25 | 25 | for (int i = 0; i < 5; i++) |
26 | 26 | threads.emplace_back(WorkerThread, std::ref(io_context), i); |
27 | 27 | |
28 | - io_context.post([] { std::cout << "Hello\n"; }); | |
28 | + for(int i=0;i<10; ++i) | |
29 | + { | |
30 | + io_context.post([] { sleep(2); std::cout << "Hello\n";}); | |
31 | + std::cout << "Posted" << std::endl; | |
32 | + } | |
29 | 33 | |
30 | 34 | std::cin.get(); |
31 | 35 | ... | ... |