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

[sugestion] tryWaitAndPop is not atomic #41

Open
xenonymdotcom opened this issue Jun 5, 2023 · 0 comments
Open

[sugestion] tryWaitAndPop is not atomic #41

xenonymdotcom opened this issue Jun 5, 2023 · 0 comments

Comments

@xenonymdotcom
Copy link

xenonymdotcom commented Jun 5, 2023

return false;

as it stands tryWaitAndPop will exit false on timeout or item inserted if the queue was empty when entered
if the return was wrapped in an if queue.empty() cause and in fact the while is superfluious
the code could be just
if (queue.empty()) { signal.wait_for(lock, std::chrono::milliseconds(_milli)); if (queue.empty()) { return false; } }
this would make the function atomic as the lock would not get released if you entered it when the queue was empty and an item was added, which as it stands could be consumed by another waiter.

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