libcds icon indicating copy to clipboard operation
libcds copied to clipboard

Data race on m_OwnerId for reentrant_spin_lock?

Open peizhaoo opened this issue 7 years ago • 1 comments

Hi guys,

We came across the reentrant_spin_lock data structure and seemed to find a potential data race. We may have missed something but just want to report it anyway.

So in the try_lock() or lock() method, they call the try_taken_lock() method, which calls the is_taken() method to check whether the current is holding the lock already. However, it doesn't seem to read the m_OwnerId variable with synchronization/happens-before, and the m_OwnerId variable is not marked as atomic variable. So while a thread is calling try_lock() which reads m_OwnerId, another thread can concurrently writes m_OwnerId, which seems like data race.

So should m_OwnerId be declared as atomic variable according to C++11?

peizhaoo avatar May 30 '18 22:05 peizhaoo

Strictly speaking you are right.

khizmax avatar May 31 '18 08:05 khizmax