Skip to content

Commit 9b37d5f

Browse files
authored
Move notify worker to outside lock
1 parent 85f4670 commit 9b37d5f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

taskflow/threadpool/privatized_threadpool.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ void BasicPrivatizedThreadpool<Func>::wait_for_all() {
677677

678678
/* A different implementation
679679
680+
680681
template < template<typename...> class Func >
681682
class BasicPrivatizedThreadpool {
682683
@@ -1036,13 +1037,12 @@ void BasicPrivatizedThreadpool<Func>::silent_async(C&& c){
10361037
if(!_workers[id]->queue.push_back(t)){
10371038
std::scoped_lock<std::mutex> lock(_mutex);
10381039
_task_queue.push_back(std::move(t));
1039-
_workers[id]->cv.notify_one();
10401040
}
10411041
else{
10421042
// Lock to make sure the worker will be notified
10431043
std::scoped_lock<std::mutex> lock(_mutex);
1044-
_workers[id]->cv.notify_one();
10451044
}
1045+
_workers[id]->cv.notify_one();
10461046
}
10471047
10481048
@@ -1073,6 +1073,7 @@ void BasicPrivatizedThreadpool<Func>::wait_for_all() {
10731073
_empty_cv.wait(lock);
10741074
}
10751075
}
1076+
10761077
*/
10771078

10781079

0 commit comments

Comments
 (0)