mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
ConcurrentQueue::cancelPending: don't reset jobsLeft to 0
Worker threads may well be executing jobs while this function is being called. If ConcurrentQueue::waitAll() is called soon enough after cancelPending(), the worker threads may still be running, but waitAll() would return immediately as jobsLeft would be nonpositive. Subtracting _queue.size() from jobsLeft sets this variable to the number of worker threads that are executing jobs at the moment. ConcurrentQueueTest::cancelPending1UserThread() passes most of the time now. But it still fails occasionally because it depends on the timing of thread scheduling, which is unreliable.
This commit is contained in:
parent
4bbd16c3b3
commit
a72fdb9ca2
@ -47,8 +47,8 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lockQueue(queueMutex);
|
||||
std::unique_lock<std::mutex> lockJobsLeft(jobsLeftMutex);
|
||||
_queue = std::queue<std::function<void(void)>>();
|
||||
jobsLeft = 0;
|
||||
jobsLeft -= _queue.size();
|
||||
_queue = {};
|
||||
}
|
||||
|
||||
void waitAll()
|
||||
|
Loading…
Reference in New Issue
Block a user