Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion be/src/util/cpu_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ int CpuInfo::max_num_numa_nodes_;
unique_ptr<int[]> CpuInfo::core_to_numa_node_;
vector<vector<int>> CpuInfo::numa_node_to_cores_;
vector<int> CpuInfo::numa_node_core_idx_;
pthread_mutex_t CpuInfo::init_mutex_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we don't need this lock, because CpuInfo is only initialized in main function.
  2. even if we need a lock, std::mutex is preferred.
  3. you don't call pthread_mutex_init() to initialize this variable, it will lead process crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem has been fixed in 1826 with same way, in which use a mutex to lock when init(). So I close this now.


static struct {
string name;
Expand Down Expand Up @@ -111,7 +112,9 @@ int64_t ParseCPUFlags(const string& values) {
}

void CpuInfo::init() {
if (initialized_) return;
pthread_mutex_lock(&init_mutex_);
if (initialized_) return;

string line;
string name;
string value;
Expand Down Expand Up @@ -173,6 +176,7 @@ void CpuInfo::init() {

_init_numa();
initialized_ = true;
pthread_mutex_unlock(&init_mutex_);
}

void CpuInfo::_init_numa() {
Expand Down
3 changes: 3 additions & 0 deletions be/src/util/cpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ class CpuInfo {
/// Array with 'max_num_cores_' entries, each of which is the index of that core in its
/// NUMA node.
static std::vector<int> numa_node_core_idx_;

// used for init in multi thread
static pthread_mutex_t init_mutex_;
};
}
#endif