cyb70289 commented on a change in pull request #12358:
URL: https://github.com/apache/arrow/pull/12358#discussion_r801345933
##########
File path: cpp/src/arrow/util/thread_pool.h
##########
@@ -373,7 +377,7 @@ class ARROW_EXPORT ThreadPool : public Executor {
State* state_;
bool shutdown_on_destroy_;
#ifndef _WIN32
- pid_t pid_;
+ std::atomic<pid_t> pid_;
Review comment:
Agreed the code should be safe in practice.
But at least in theory, I think it still violates data race free rule.
E.g., TSAN will complain below code.
```
#include <mutex>
#include <thread>
std::mutex g_mtx;
int g_i = 0;
void f() {
if (g_i == 0) {
std::lock_guard<std::mutex> lk(g_mtx);
if (g_i == 0) {
g_i = 1;
}
}
}
int main(void) {
std::thread t1(f), t2(f), t3(f), t4(f);
t1.join(); t2.join(); t3.join(); t4.join();
return 0;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]