Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreadSafeQueue is not thread safe for multiple readers #134

Open
nahikia2 opened this issue Feb 29, 2024 · 0 comments
Open

ThreadSafeQueue is not thread safe for multiple readers #134

nahikia2 opened this issue Feb 29, 2024 · 0 comments

Comments

@nahikia2
Copy link

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant