7 Commits

Author SHA1 Message Date
Igor Kushnir
e8b5f42e75 ConcurrentQueue::nextJob: notify all _waitVar threads
Replace _waitVar.notify_one() with _waitVar.notify_all(). This was the
only hurdle to documenting ConcurrentQueue::waitAll() as thread-safe.

ConcurrentQueueTest::waitAllFromMultipleThreads() passes instead of
hanging now.
2021-12-29 09:36:44 +01:00
Igor Kushnir
b43e3383d5 ConcurrentQueue::cancelPending: return the number of canceled jobs
The return value can be used to make
ConcurrentQueueTest::cancelPending1UserThread() non-flaky. It may also
be useful to non-testing code.

Improve the performance of cancelPending() by locking the two mutexes
separately and minimizing the locking time.
2021-12-29 09:36:44 +01:00
Igor Kushnir
a72fdb9ca2 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.
2021-12-29 09:36:44 +01:00
Igor Kushnir
228fe1284e Fix a typo in ConcurrentQueue::cancelPending function name 2021-12-29 09:36:44 +01:00
Luis Ángel San Martín
93596a4972 Restore needed lock 2021-02-08 09:02:19 +01:00
Luis Ángel San Martín
4c93c70de6 Use the right mutex when the queue is modified 2021-02-08 08:32:42 +01:00
Luis Ángel San Martín
fa5ce25425 Add concurrent queue based on lambdas 2021-01-14 09:03:17 +01:00