This shows you the differences between two versions of the page.
— | blog:2022:06:22:2022-06-22_-_tsan_bug [2022/06/22 21:56] (current) – created basz | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 2022-06-22 - TSAN bug ====== | ||
+ | while preparing [[: | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | auto ready = false; | ||
+ | std::mutex m; | ||
+ | std:: | ||
+ | |||
+ | std::thread th{ [&]{ | ||
+ | // thread 1 | ||
+ | std:: | ||
+ | #if 0 | ||
+ | // OK! | ||
+ | cv.wait( lock, [&]{ return ready; } ); | ||
+ | #endif | ||
+ | #if 0 | ||
+ | // ERROR! | ||
+ | cv.wait_until( lock, std:: | ||
+ | #endif | ||
+ | #if 1 | ||
+ | // ERROR! | ||
+ | cv.wait_for( lock, std:: | ||
+ | #endif | ||
+ | } }; | ||
+ | |||
+ | { | ||
+ | // thread 2 | ||
+ | std:: | ||
+ | std:: | ||
+ | ready = true; | ||
+ | cv.notify_one(); | ||
+ | } | ||
+ | |||
+ | th.join(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | after compiling it with: | ||
+ | |||
+ | g++ -fsanitize=thread | ||
+ | |||
+ | we can see a very colorful output, indicating double-locking and race condition! | ||
+ | |||
+ | {{: | ||
+ | |||
+ | the same issue is reported with both '' | ||
+ | |||
+ | here are the bugs i found already reported for this: | ||
+ | * {{https:// | ||
+ | * {{https:// | ||
+ | |||
+ | i've spent quite a bit of time today, trying to narrow down the issue and making it small and reproducible issue. then it turned out it's a know problem. life... ;) | ||
+ | |||
+ | the problem has been observed on UTs. even though here it was false-positive, |