From 369ed9e2beb7cb37e83534ecc31d0023ee5d0abf Mon Sep 17 00:00:00 2001 From: FrK5E Date: Tue, 2 Sep 2025 21:37:42 +0200 Subject: [PATCH 1/2] compiled with gcc 15.1, boost 1.88 --- Chapter_09/9x02-executor_work_guard.cpp | 2 +- Chapter_09/9x04-post_and_dispatch.cpp | 5 +++-- Chapter_09/9x06-exception_handling.cpp | 2 +- Chapter_09/9x08-multithreaded_io_context_main_thread.cpp | 4 ++-- Chapter_09/9x18-explicit_strands.cpp | 2 +- Chapter_11/CMakeLists.txt | 2 ++ Chapter_12/12x22-testing_async_function_with_event_loop.cpp | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Chapter_09/9x02-executor_work_guard.cpp b/Chapter_09/9x02-executor_work_guard.cpp index c0cf950..10d4d44 100644 --- a/Chapter_09/9x02-executor_work_guard.cpp +++ b/Chapter_09/9x02-executor_work_guard.cpp @@ -9,7 +9,7 @@ void background_task(boost::asio::io_context& io_context) { // Waiting for 2 seconds before posting work std::this_thread::sleep_for(2s); std::cout << "Posting a background task.\n"; - io_context.post([]() { std::cout << "Background task completed!\n"; }); + boost::asio::post( io_context, []() { std::cout << "Background task completed!\n"; }); } int main() { diff --git a/Chapter_09/9x04-post_and_dispatch.cpp b/Chapter_09/9x04-post_and_dispatch.cpp index 90680b6..ee4ff45 100644 --- a/Chapter_09/9x04-post_and_dispatch.cpp +++ b/Chapter_09/9x04-post_and_dispatch.cpp @@ -1,12 +1,13 @@ #include +#include #include int main() { boost::asio::io_context io_context; - io_context.post([] { std::cout << "This will always run asynchronously.\n"; }); + boost::asio::post( io_context, [] { std::cout << "This will always run asynchronously.\n"; }); - io_context.dispatch([] { std::cout << "This might run immediately or be queued.\n"; }); + boost::asio::dispatch(io_context, [] { std::cout << "This might run immediately or be queued.\n"; }); io_context.run(); return 0; diff --git a/Chapter_09/9x06-exception_handling.cpp b/Chapter_09/9x06-exception_handling.cpp index a5070b6..7e52199 100644 --- a/Chapter_09/9x06-exception_handling.cpp +++ b/Chapter_09/9x06-exception_handling.cpp @@ -13,7 +13,7 @@ void my_handler() { } void post_handler(boost::asio::io_context& io_context) { - io_context.post(my_handler); + boost::asio::post( io_context, my_handler); } int main() { diff --git a/Chapter_09/9x08-multithreaded_io_context_main_thread.cpp b/Chapter_09/9x08-multithreaded_io_context_main_thread.cpp index f1a7192..032a2b0 100644 --- a/Chapter_09/9x08-multithreaded_io_context_main_thread.cpp +++ b/Chapter_09/9x08-multithreaded_io_context_main_thread.cpp @@ -5,7 +5,7 @@ void long_running_task(boost::asio::io_context& io_context, int task_duration) { std::cout << "Background task started: Duration = " << task_duration << " seconds.\n"; std::this_thread::sleep_for(std::chrono::seconds(task_duration)); - io_context.post([&io_context]() { + boost::asio::post( io_context, [&io_context]() { std::cout << "Background task completed.\n"; io_context.stop(); }); @@ -16,7 +16,7 @@ int main() { auto work_guard = boost::asio::make_work_guard(io_context); - io_context.post([&io_context]() { + boost::asio::post( io_context, [&io_context]() { std::thread t(long_running_task, std::ref(io_context), 2); std::cout << "Detaching thread" << std::endl; t.detach(); diff --git a/Chapter_09/9x18-explicit_strands.cpp b/Chapter_09/9x18-explicit_strands.cpp index dcf4c99..b31bf51 100644 --- a/Chapter_09/9x18-explicit_strands.cpp +++ b/Chapter_09/9x18-explicit_strands.cpp @@ -25,7 +25,7 @@ class Logger { void log(const std::string message) { //strand_.post(std::bind(&Logger::do_log, this, message)); - strand_.post([this, message]() { do_log(message); }); + boost::asio::post( strand_, [this, message]() { do_log(message); }); } private: diff --git a/Chapter_11/CMakeLists.txt b/Chapter_11/CMakeLists.txt index 7500d4a..40f6231 100644 --- a/Chapter_11/CMakeLists.txt +++ b/Chapter_11/CMakeLists.txt @@ -1,6 +1,8 @@ # Output directory set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BINARY_DIR}/Chapter_11) +find_package( spdlog REQUIRED ) + # Create executable for each cpp file file(GLOB SOURCES "*.cpp") foreach(SOURCE ${SOURCES}) diff --git a/Chapter_12/12x22-testing_async_function_with_event_loop.cpp b/Chapter_12/12x22-testing_async_function_with_event_loop.cpp index 6b7f2bc..b2b46a6 100644 --- a/Chapter_12/12x22-testing_async_function_with_event_loop.cpp +++ b/Chapter_12/12x22-testing_async_function_with_event_loop.cpp @@ -7,7 +7,7 @@ using namespace std::chrono_literals; void asyncFunc(boost::asio::io_context& io_context, std::function callback) { - io_context.post([callback]() { + boost::asio::post( io_context, [callback]() { std::this_thread::sleep_for(100ms); callback(42); }); From f5674f37c07fbbe01d770eb6110181e3e841be57 Mon Sep 17 00:00:00 2001 From: FrK5E Date: Tue, 2 Sep 2025 21:37:54 +0200 Subject: [PATCH 2/2] git ignore update --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6a62326..44c0df7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ CMakeFiles Makefile *.cmake CMakeCache.txt +.cache +compile_commands.json