-
Notifications
You must be signed in to change notification settings - Fork 1k
ThreadSanitizerAtomicOperations
Alexander Potapenko edited this page Aug 31, 2015
·
1 revision
ThreadSanitizer
understands various flavors of compiler built-in atomic operations:
- __sync_fetch_and_add. This does not support atomic load operation and precise memory ordering.
- __c11_atomic_fetch_add. This is supported only by clang.
- __atomic_load_n. This requires relatively fresh compiler (at least gcc 4.7).
If std::atomic<> type is implemented using some sort of compiler built-ins (e.g. libc++), then ThreadSanitizer
will understand it as well.
Also ThreadSanitizer
runtime provides own set of atomic operations of the form:
__tsan_atomic8 __tsan_atomic8_load(const volatile __tsan_atomic8 *a, __tsan_memory_order mo);
The full list is available here.
So there are 3 options:
- Use only compiler intrinsics (or std::atomic<>).
- Use home-grown atomic operations for old compilers, for newer compilers use atomic_load_n atomic operations.
- Use home-grown atomic operations for normal build, under tsan use tsan_atomic8_load atomic operations.
You can see an example of option 2 here.