You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// this would be called from the main threadvoidWaitGroup::Add(int i) {
std::unique_lock<std::mutex> l(mu_);
counter_ += i;
}
// this would be called from the worker threadvoidWaitGroup::Done() {
{
std::unique_lock<std::mutex> l(mu_);
counter_--;
}
cv_.notify_all();
}
// this would be called from the main threadvoidWaitGroup::Wait() {
std::unique_lock<std::mutex> l(mu_);
cv_.wait(l, [&] { return counter_ <= 0; });
}
@qiandu2006@yoda-jm thank you very much for your issue. I will update it once I have again a c++ development environment setup. Feel free to create a PR. I appreciate your review, thank you!
I leave it open until I have time to fix it or someone has sent a PR.
I think that the implementation is racy, especially the Add/Done side.
According to this link https://www.modernescpp.com/index.php/c-core-guidelines-be-aware-of-the-traps-of-condition-variables atomic variable modification should be made under the lock
The text was updated successfully, but these errors were encountered: