Closed GoogleCodeExporter closed 9 years ago
Hi,
Yes, volatile is not related to multi-threading in any way. So, yes, you have a
data race and undefined behavior according to C/C++ standards. If you are using
atomics-based fine-grained concurrent algorithms, you really need some good
atomics API. When you have such an API, tsan will either understand it, or you
can teach tsan to understand it.
tsan understands __sync builtin atomics, __atomic builtin atomics, __c11_atomic
builtin atomics, std::atomic<> if it's implemented on top of builtin atomics.
If you use sufficiently new compilers, I would recommend using __atomic atomics.
If you need to support old compilers as well, then you need to do something
along the lines:
int my_atomic_int_load_acquire(int *p) {
#ifdef OLD_COMPILER
use your own implementation here
#else // NEW_COMPILER
return __atomic_load_n(p, ATOMIC_ACQUIRE);
#endif
}
this way tsan will automatically understand all your concurrent algorithms,
because it's based on a new compiler.
Original comment by dvyu...@google.com
on 15 Nov 2013 at 9:32
Tsan is not going to acknowledge volatile as synchronization.
If they are spread over codebase, then this is a bug.
If they are used in atomics implementation, that the implementation must be
somehow annotated for tsan.
Original comment by dvyu...@google.com
on 26 Dec 2013 at 2:22
Adding Project:ThreadSanitizer as part of GitHub migration.
Original comment by gli...@google.com
on 30 Jul 2015 at 9:21
Original issue reported on code.google.com by
chatelet...@gmail.com
on 15 Nov 2013 at 9:20