Yibo Cai created ARROW-7464: ------------------------------- Summary: [C++][util]: Refine CpuInfo singleton with std::call_once Key: ARROW-7464 URL: https://issues.apache.org/jira/browse/ARROW-7464 Project: Apache Arrow Issue Type: Improvement Components: C++ Reporter: Yibo Cai Assignee: Yibo Cai
CpuInfo singleton is created and initialized on first invocation of [CpuInfo::GetInstance()|https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/cpu_info.cc#L188-L195]. All calls afterwards return reference to the same instance. Current code uses std::mutex to make sure that CpuInfo is created only once, but it introduces unnecessary overhead for later calls. Concurrent threads getting the created instance should not block each other. Replace std::mutex with std::call_once to fix this issue. References: [1] https://en.cppreference.com/w/cpp/thread/call_once [2] http://www.modernescpp.com/index.php/thread-safe-initialization-of-data -- This message was sent by Atlassian Jira (v8.3.4#803005)