Resolve race on approx_time_ in FastClock.

InitType should hold a lock before storing to approx_time_, which is later
read by the background worker.  When the worker is actively running (i.e., not
blocked on bg_cond_) it holds bg_mutex_.

InitType is called during benchmark setup only, so any contention induced for
the mutex should not have performance/accuracy consequences.
This commit is contained in:
Chris Kennelly 2014-05-05 02:11:54 -04:00
parent efb9c302cc
commit 2c9b29c9ff
1 changed files with 1 additions and 0 deletions

View File

@ -577,6 +577,7 @@ class State::FastClock {
// function starts running - see UseRealTime). // function starts running - see UseRealTime).
void InitType(Type type) { void InitType(Type type) {
type_ = type; type_ = type;
mutex_lock l(&bg_mutex_);
std::atomic_store(&approx_time_, NowMicros()); std::atomic_store(&approx_time_, NowMicros());
} }