Potential data races when accessing variable stderr in function PthreadCall
- Dominant language
- C++
- Stars
- 39.4k
- Forks
- 8.2k
- PR merge metrics
- No merged PRs in 30d
Description
Hi all,
Our bug scanner has reported a data race issue at [env_posix.cc#L551](https://github.com/google/leveldb/blob/master/util/env_posix.cc#L551)
Followings are code snippets.
```c++
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(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
Contributor guide
Assessment
This issue has not been assessed yet.