staticanalysis / data-race-test

Automatically exported from code.google.com/p/data-race-test
0 stars 0 forks source link

False positive with asm release semantic and atomic_compare_and_exchange #116

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Full story described here https://github.com/OpenImageIO/oiio/issues/720.

Short story : 
https://github.com/OpenImageIO/oiio/blob/master/src/include/thread.h l.542 
implements a spin lock.
TSan reports data race with one write l.568
> // Fastest way to do it is with a store with "release" semantics
> __asm__ __volatile__("": : :"memory");
> m_locked = 0;  <<<< this line

and a compare and exchange l.597
> return atomic_compare_and_exchange (&m_locked, 0, 1);

m_locked is of type `volatile int`.

There is already a debate in the above mentioned thread about the usefulness of 
volatile. I'm not a low level concurrency expert so I actually don't know if 
the asm code has the correct semantic or not.

Environment:
- clang version 3.3 (tags/RELEASE_33/final)
- Arch Linux x86_64, kernel 3.11.6-1-ARCH

Original issue reported on code.google.com by chatelet...@gmail.com on 15 Nov 2013 at 7:41

GoogleCodeExporter commented 9 years ago
Are you using the old Valgrind-based tsan, or the new clang-based tsan?

Original comment by dvyu...@google.com on 15 Nov 2013 at 8:08

GoogleCodeExporter commented 9 years ago
New clang based tsan

Original comment by chatelet...@gmail.com on 15 Nov 2013 at 8:12

GoogleCodeExporter commented 9 years ago
Please move the request to:
https://code.google.com/p/thread-sanitizer/issues/list
This project is for old tsan and is unmaintained.

Original comment by dvyu...@google.com on 15 Nov 2013 at 8:14