You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// bad case: data race detectedvoidtestDataRace()
{
int32_t counter = 0;
std::thread t1([&counter] {
if (!counter)
counter = 1;
});
std::thread t2([&counter] {
if (!counter)
counter = 2;
});
t1.join();
t2.join();
}
Not detected when use atomic
// For user it is a bad case, but not detectedvoidtestDataRaceAtomic()
{
std::atomic<int32_t> counter = 0;
std::thread t1([&counter] {
if (!counter)
counter = 1;
});
std::thread t2([&counter] {
if (!counter)
counter = 2;
});
t1.join();
t2.join();
}
As a user's perspective the behavior is unexpected.
The text was updated successfully, but these errors were encountered:
It still happens in trunk, but it doesn't look like a bug to me.
From what I understand, TSAN only detects data races (as in, the kind of UB), not race conditions in general (as in, logic errors in concurrent code that are not UB per se). (1, 2)
Env
Test case
As a user's perspective the behavior is unexpected.
The text was updated successfully, but these errors were encountered: