From b70c604efb4ca644557b9a08479cb7dbb5c95195 Mon Sep 17 00:00:00 2001 From: RaymonYip-NUC11 <2205929492@qq.com> Date: Sun, 10 Sep 2023 17:54:00 +0800 Subject: [PATCH] fix: listing_2.6 sub thread is not running --- listings/listing_2.6.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/listings/listing_2.6.cpp b/listings/listing_2.6.cpp index f08fff6..3e9f660 100644 --- a/listings/listing_2.6.cpp +++ b/listings/listing_2.6.cpp @@ -22,6 +22,8 @@ class scoped_thread void do_something(int& i) { ++i; + if (i % 100000 == 0) + printf("%d\n", i); } struct func @@ -45,7 +47,8 @@ void do_something_in_current_thread() void f() { int some_local_state; - scoped_thread t(std::thread(func(some_local_state))); + // scoped_thread t(std::thread(func(some_local_state))); + scoped_thread t(std::move(std::thread(func(some_local_state)))); do_something_in_current_thread(); }