commit | c8154bde8758d1ffdd0ffdbdeac7ac9daa1a09ff | [log] [tgz] |
---|---|---|
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | Tue Jan 26 17:43:19 2016 +0900 |
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | Tue Jan 26 17:43:19 2016 +0900 |
tree | 2a3e62f8f5eb56f4563242fab0d091f86aca2d55 | |
parent | 12f41b62362fa5ef185b3a90da96918ae3b88428 [diff] [blame] |
[C++] Fix a race in stats.cc
diff --git a/stats.cc b/stats.cc index ec11e7f..ec509d8 100644 --- a/stats.cc +++ b/stats.cc
@@ -27,6 +27,7 @@ namespace { +mutex g_mu; vector<Stats*>* g_stats; DEFINE_THREAD_LOCAL(double, g_start_time); @@ -34,6 +35,7 @@ Stats::Stats(const char* name) : name_(name), elapsed_(0), cnt_(0) { + unique_lock<mutex> lock(g_mu); if (g_stats == NULL) g_stats = new vector<Stats*>; g_stats->push_back(this);