-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Potential data races when accessing variable stderr in function PthreadCall #499
Copy link
Copy link
Open
Labels
Description
Hi all,
Our bug scanner has reported a data race issue at env_posix.cc#L551
Followings are code snippets.
void PosixEnv::Schedule(void (*function)(void*), void* arg) {
...
if (!started_bgthread_) {
started_bgthread_ = true;
PthreadCall(
"create thread",
pthread_create(&bgthread_, NULL, &PosixEnv::BGThreadWrapper, this));
}
...
PthreadCall("unlock", pthread_mutex_unlock(&mu_));
}
void BGThread();
static void* BGThreadWrapper(void* arg) {
reinterpret_cast<PosixEnv*>(arg)->BGThread();
return NULL;
}
void PosixEnv::BGThread() {
while (true) {
...
PthreadCall("unlock", pthread_mutex_unlock(&mu_));
...
}
}
void PthreadCall(const char* label, int result) {
if (result != 0) {
fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
...
}
}The call trace is as follows:
PosixEnv::Schedule->PthreadCall
and
PosixEnv::Schedule->BGThreadWrapper->PosixEnv::BGThread->PthreadCall
The race may be rarely triggered, but it would corrupt the log when occured.
SourceBrella Inc.,
Yu
Reactions are currently unavailable