| Issue |
52942
|
| Summary |
ThreadSanitizer: false report about data race
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Fedr
|
The program as follows is valid:
```
#include <atomic>
#include <iostream>
#include <future>
int state = 0;
std::atomic_int a = 0;
void foo(int from, int to)
{
for (int i = 0; i < 10; i++)
{
while (a.load(std::memory_order_relaxed) != from) {}
std::atomic_thread_fence(std::memory_order_acquire);
state++;
a.store(to, std::memory_order_release);
}
}
int main()
{
auto x = std::async(std::launch::async, foo, 0, 1);
auto y = std::async(std::launch::async, foo, 1, 0);
}
```
The access to `state` variable is not a data race, because each thread before the modification executes `atomic_thread_fence` to see the results of the other thread, and after the modification executes atomic store with `memory_order_release`. But the sanitizer erroneously reports data race. Demo: https://gcc.godbolt.org/z/9cY3aM3cz
Related discussion: https://stackoverflow.com/q/70542993/7325599
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs