nasa-jpl / fastcat

C++ EtherCAT Device Command & Control Library
Other
42 stars 11 forks source link

ThreadSafeQueue is not thread safe for multiple readers #134

Open nahikia2 opened 6 months ago

nahikia2 commented 6 months ago

Calling front() and pop() when the queue is empty is undefined behavior. There are no operations provided that check empty() and then access the container while holding the mutex the entire time.

If there are two threads that look like this:

while(true) { if (!queue.empty()) { queue.pop(); } }

It is likely that the queue is not empty when one thread checks the conditional statement, but it is empty when it tries to call pop().