Commit fdf44c8d526a67e11ef0aeba401fe9df08d2ffce
1 parent
ad581d42
Simplifier muthithreading
Showing
2 changed files
with
2 additions
and
2 deletions
12-threads.cpp
@@ -17,7 +17,7 @@ int main(void) { | @@ -17,7 +17,7 @@ int main(void) { | ||
17 | 17 | ||
18 | auto io_svc = std::make_shared<asio::io_context>(); | 18 | auto io_svc = std::make_shared<asio::io_context>(); |
19 | 19 | ||
20 | - auto worker = std::make_shared<asio::io_context::work>(*io_svc); | 20 | + asio::executor_work_guard work_guard(io_svc->get_executor()); //prevent run() from exiting immediately after all work is done |
21 | 21 | ||
22 | std::cout << "Press ENTER key to exit!" << std::endl; | 22 | std::cout << "Press ENTER key to exit!" << std::endl; |
23 | 23 |
13-daytime8.cpp
@@ -95,7 +95,7 @@ int main() { | @@ -95,7 +95,7 @@ int main() { | ||
95 | try { | 95 | try { |
96 | auto io_context = std::make_shared<asio::io_context>(); | 96 | auto io_context = std::make_shared<asio::io_context>(); |
97 | 97 | ||
98 | - auto worker = std::make_shared<asio::io_context::work>(*io_context); | 98 | + asio::executor_work_guard work_guard(io_svc->get_executor()); //prevent run() from exiting immediately after all work is done |
99 | 99 | ||
100 | std::vector<std::thread> threads; | 100 | std::vector<std::thread> threads; |
101 | 101 |