From 61b7b123430f2a16524f30fbe7500834876447af Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Thu, 26 Jan 2017 18:39:07 -0500 Subject: [PATCH] PARQUET-846: CpuInfo::Init() is not thread safe Author: Deepak Majeti Closes #230 from majetideepak/PARQUET-846 and squashes the following commits: 9007986 [Deepak Majeti] PARQUET-846: CpuInfo::Init() is not thread safe Change-Id: I33bef39d6291dfe207bfc248cf7ce571f6308ad3 --- cpp/src/parquet/util/cpu-info.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpp/src/parquet/util/cpu-info.cc b/cpp/src/parquet/util/cpu-info.cc index e8f6faced027c..f56d423262aa6 100644 --- a/cpp/src/parquet/util/cpu-info.cc +++ b/cpp/src/parquet/util/cpu-info.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,7 @@ int64_t CpuInfo::cache_sizes_[L3_CACHE + 1]; int64_t CpuInfo::cycles_per_ms_; int CpuInfo::num_cores_ = 1; string CpuInfo::model_name_ = "unknown"; // NOLINT +static std::mutex cpuinfo_mutex; static struct { string name; @@ -76,6 +78,10 @@ int64_t ParseCPUFlags(const string& values) { } void CpuInfo::Init() { + std::lock_guard cpuinfo_lock(cpuinfo_mutex); + + if (initialized()) { return; } + string line; string name; string value;