public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103878] New: ThreadSanitizer: false report about data race
@ 2021-12-31 15:28 fchelnokov at gmail dot com
  2021-12-31 18:53 ` [Bug c++/103878] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fchelnokov at gmail dot com @ 2021-12-31 15:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103878

            Bug ID: 103878
           Summary: ThreadSanitizer: false report about data race
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/103878] ThreadSanitizer: false report about data race
  2021-12-31 15:28 [Bug c++/103878] New: ThreadSanitizer: false report about data race fchelnokov at gmail dot com
@ 2021-12-31 18:53 ` redi at gcc dot gnu.org
  2022-01-01  6:24 ` [Bug sanitizer/103878] " pinskia at gcc dot gnu.org
  2022-01-01  6:48 ` fchelnokov at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-31 18:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103878

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Isn't this simply the documented limitation of tsan?
https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.races

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug sanitizer/103878] ThreadSanitizer: false report about data race
  2021-12-31 15:28 [Bug c++/103878] New: ThreadSanitizer: false report about data race fchelnokov at gmail dot com
  2021-12-31 18:53 ` [Bug c++/103878] " redi at gcc dot gnu.org
@ 2022-01-01  6:24 ` pinskia at gcc dot gnu.org
  2022-01-01  6:48 ` fchelnokov at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-01  6:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103878

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Since it was reported that clang/LLVM have the same issue, is there a bug
report about that?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug sanitizer/103878] ThreadSanitizer: false report about data race
  2021-12-31 15:28 [Bug c++/103878] New: ThreadSanitizer: false report about data race fchelnokov at gmail dot com
  2021-12-31 18:53 ` [Bug c++/103878] " redi at gcc dot gnu.org
  2022-01-01  6:24 ` [Bug sanitizer/103878] " pinskia at gcc dot gnu.org
@ 2022-01-01  6:48 ` fchelnokov at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-01  6:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103878

--- Comment #3 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Bugreport for Clang/LLVM: https://github.com/llvm/llvm-project/issues/52942

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-01  6:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 15:28 [Bug c++/103878] New: ThreadSanitizer: false report about data race fchelnokov at gmail dot com
2021-12-31 18:53 ` [Bug c++/103878] " redi at gcc dot gnu.org
2022-01-01  6:24 ` [Bug sanitizer/103878] " pinskia at gcc dot gnu.org
2022-01-01  6:48 ` fchelnokov at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).