4 ms·
Anyone making multithreaded code in c++ should be using thread sanitizer. Whether or not a specific datastruture crashes more in multithreaded code will not mat
by mathiasgredal 3y ago
Anyone making multithreaded code in c++ should be using thread sanitizer. Whether or not a specific datastruture crashes more in multithreaded code will not matter, since tsan will issue a warning on all unsafe accesses.
- uluyol 3y agoJust a minor point: while tsan is extremely helpful, it is not guaranteed to catch all data races.
- jenadine 3y agoMatches my experience. It does sometimes warn about race in 3rd party library (that are actual race usually, even though there might not be issues in practice) but then you can add suppression when fixing upstream is not an option.
- moregrist 3y agoUnfortunately tsan is a pretty big performance hit (5x-15x with 5x-10x increase in memory) and has a non-zero false positive rate. So it’s not a “use almost always during development thing” like the address sanitizer is. That said, it’s can be really helpful when you suspect a race condition.
- 1over137 3y agoIn my experience, it has a near-zero false positive rate though.
- intelVISA 3y agoAfter enough YOE you can perform tsan-like static analysis just by reading the code.
- nayuki 3y agoYOE = years of experience
- adrianN 3y agoMaybe if you work on a tiny codebase.
- UncleMeat 3y agoGiven how many times I've seen people on the C++ standards committee make a concurrency mistake, I don't believe you. Thread safety is extraordinarily difficult to reason about by looking at code once you've moved beyond very basic designs. Tsan is also not static analysis.
- deleted 3y ago[deleted]
- david2ndaccount 3y agoTsan doesn’t understand mach semaphores unfortunately.
- JonChesterfield 3y agoThread sanitizer doesn't understand fences. It seems relacy is the only one that does. If anyone knows how to make relacy run a somewhat fair scheduler please let me know - it told me a server thread that waited for work never made any progress, but it also never gave a client thread any cycles to submit work so that wasn't very informative. (edit: just occurred to me I can probably fake it adequately by having a yield that makes the current thread start playing the role of the other service, coroutine style)