Wait until there is any work item to be done (#208)

This is for handling a rare case when all threads are free without any work (working_cnt == 0) but there exist some work items that are not yet done or not yet started to be processed.
This commit is contained in:
Mobin Asri 2023-08-17 16:31:48 -07:00 committed by GitHub
parent 0df91cc414
commit 01c6122931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -258,7 +258,7 @@ void tpool_wait(tpool_t *tp)
/* working_cond is dual use. It signals when we're not stopping but the
* working_cnt is 0 indicating there isn't any work processing. If we
* are stopping it will trigger when there aren't any threads running. */
if ((!tp->stop && tp->working_cnt != 0) || (tp->stop && tp->thread_cnt != 0))
if ((!tp->stop && (tp->working_cnt != 0 || tm->work_first != NULL)) || (tp->stop && tp->thread_cnt != 0))
scond_wait(tp->working_cond, tp->work_mutex);
else
break;