Remove ConcurrentQueue::joinAll()

This function is called only from ~ConcurrentQueue(). joinAll() is not
thread-safe and it cannot be called earlier without introducing a null
state. Moving the function's implementation into the definition of
~ConcurrentQueue() makes the code clearer. Removing joinAll() also
allows to establish and document invariants for two data members.

Assert consistency between jobsLeft and _queue in ~ConcurrentQueue().
This commit is contained in:
Igor Kushnir
2021-03-18 09:51:59 +02:00
committed by Luis Ángel San Martín
parent 61cd245037
commit 4cb542c8cc
2 changed files with 12 additions and 24 deletions

View File

@ -36,10 +36,11 @@ public:
void waitAll();
private:
//! @invariant all worker threads are joinable until the destructor is called.
std::vector<std::thread> threads;
std::queue<Job> _queue;
std::size_t jobsLeft = 0; //!< @invariant jobsLeft >= _queue.size()
bool bailout = false;
bool bailout = false; //!< @invariant is false until the destructor is called.
std::condition_variable jobAvailableVar;
std::condition_variable _waitVar;
std::mutex jobsLeftMutex;
@ -47,7 +48,6 @@ private:
void nextJob();
void finalizeJobs(std::size_t count);
void joinAll();
};
}