[Bug sanitizer/97868] warn about using fences with TSAN
ispavlick at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Sep 11 06:13:08 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97868
pavlick <ispavlick at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ispavlick at gmail dot com
--- Comment #5 from pavlick <ispavlick at gmail dot com> ---
Why is there false positive and no warning about the unsupported feature
(atomic_thread_fence)?
[code]
#include <thread>
#include <atomic>
#include <vector>
#include <chrono>
using namespace std;
class Test {
atomic_flag m_spin_lock;
vector<int> m_data;
public:
void add() {
while (m_spin_lock.test_and_set(memory_order_relaxed))
this_thread::yield();
atomic_thread_fence(memory_order_acquire);
while (true) {
this_thread::sleep_for(300ms);
m_data.push_back(4);
}
m_spin_lock.clear(memory_order_release);
}
void read() {
size_t sz;
if (! m_spin_lock.test_and_set(std::memory_order_acquire)) {
sz = m_data.size();
m_spin_lock.clear(std::memory_order_release);
}
(void)sz;
}
}test;
int main() {
jthread rt(&Test::read, &test);
this_thread::sleep_for(10ms);
test.add();
}
[/code]
$ g++ 3.cc -std=c++20 -Wtsan -Wall -fsanitize=thread
More information about the Gcc-bugs
mailing list