Repository navigation
fix(mutex): hold lock during notify_all in Barrier::wait to prevent teardown race (fixes #1672) - #2325
Merged
Conversation
…eardown race (fixes google#1672)
dmah42
previously approved these changes
Oct 9, 2026
Member
|
nice catch. thanks. can you fix the formatting? |
Contributor
Author
|
Updated the formatting in test/benchmark_gtest.cc to match clang-format. Thanks @dmah42! |
dmah42
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
In Barrier::wait() (src/mutex.h), MutexLock ml(lock_) was enclosed in an inner block that released the mutex before calling phase_condition_.notify_all(). When other threads awakened by createBarrier() finish their work and immediately destroy or free the Barrier instance, the last thread proceeds to call phase_condition_.notify_all() on a deallocated or destructed condition variable, resulting in a segmentation fault / null pointer dereference (#1672).
Fix Approach
Extend MutexLock ml(lock_) to cover phase_condition_.notify_all(). Holding the lock until after notify_all() completes ensures the Barrier object and its condition variable remain valid and protected from premature destruction by waking peer threads.
Verification
Added regression tests to test/benchmark_gtest.cc:
All tests pass cleanly with zero sanitizer warnings.