Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread Sanitizer reports multiple data races #35

Open
mopleen opened this issue Aug 5, 2020 · 3 comments
Open

Thread Sanitizer reports multiple data races #35

mopleen opened this issue Aug 5, 2020 · 3 comments

Comments

@mopleen
Copy link

mopleen commented Aug 5, 2020

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

@mattiasflodin
Copy link
Owner

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.

@mattiasflodin
Copy link
Owner

mattiasflodin commented Jul 20, 2022

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.

@mattiasflodin
Copy link
Owner

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

@mattiasflodin mattiasflodin reopened this Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants