mattiasflodin/reckless

Thread Sanitizer reports multiple data races

Opened this issue ยท 3 comments

Hi Mattias!

Thanks for the great library!

Are you aware of the warnings that thread sanitizer reports? They're probably false positives (I hope ๐Ÿ˜„) but nevertheless they would hide real warnings. Could you please have a look?

Small example:
reckless_tsan.cpp.txt

Build and run like this:

g++ reckless_tsan.cpp -O2 -fsanitize=thread -lreckless && ./a.out

Getting these warnings:
tsan_warnings.txt

Hi,

I have looked at a couple of the warnings and it appears that ThreadSanitizer is not able to handle lockless code. If the reported issues were true positives then I can't imagine that the library would run without failing during all the benchmark tests. In the paper the authors say that "Unless you have lock-free synchronization (which you will have to annotate), every reported race will be real."

I understand that it's undesirable that the library causes noise that hides justified warnings in your code though. So I will consider this a feature request to add annotations for the lock-free synchronization, if possible. If you believe you have found a real data race then I'd be very interested to learn about it.

I have now spent several hours trying to add __tsan_acquire() and __tsan_release() annotations to the writes and reads. Maybe I'm not understanding how to use them correctly (the documentation is pretty much non-existent) but it seems to me like a game of whack-a-mole: every write to every member variable in a message being pushed to the ring buffer has to be annotated separately which becomes infeasible when the writes and reads come from user-injectable class policies (like custom fields) or you have custom objects being pushed as parameters to the formatter.

Failing that, I tried to add __attribute__((no_sanitize("thread"))) to the write function and output worker, but since writes and reads happen in other places such as the std::tuple's copy constructor and not directly in those functions (I assume), that annotation also has no effect.

So I'm closing this for now but if anybody understands how to use these annotations in a way that works for reckless I'd be happy to know.

On second thought, I'm reopening this for visibility.