Data race on m_OwnerId for reentrant_spin_lock?
peizhaoo opened this issue · 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?
Strictly speaking you are right.