File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -82,26 +82,26 @@ class ThreadPoolExecutor : public Executor {
8282 ThreadPoolExecutor () = delete ;
8383
8484 void stop () {
85+ Stop = true ;
86+ Cond.notify_all ();
87+ ThreadsCreated.get_future ().wait ();
88+
89+ std::vector<std::thread> ThreadsToJoin;
8590 {
8691 std::lock_guard<std::mutex> Lock (Mutex);
87- if (Stop)
88- return ;
89- Stop = true ;
92+ ThreadsToJoin.swap (Threads);
9093 }
91- Cond.notify_all ();
92- ThreadsCreated.get_future ().wait ();
93- }
9494
95- ~ThreadPoolExecutor () override {
96- stop ();
9795 std::thread::id CurrentThreadId = std::this_thread::get_id ();
98- for (std::thread &T : Threads )
96+ for (std::thread &T : ThreadsToJoin )
9997 if (T.get_id () == CurrentThreadId)
10098 T.detach ();
10199 else
102100 T.join ();
103101 }
104102
103+ ~ThreadPoolExecutor () override { stop (); }
104+
105105 struct Creator {
106106 static void *call () { return new ThreadPoolExecutor (strategy); }
107107 };
You can’t perform that action at this time.
0 commit comments