I think the sys::unix::rwlock implementation is incorrect in the sense that it has undefined behavior, for two reasons:
The access to write_locked is not properly synchronized: In read, we access write_locked even if pthread_rwlock_rdlock failed. This is fixed.
- Worse, POSiX read-write locks have UB when the thread holding the write lock attempts to acquire it again -- and yet nothing is stopping exactly that from happening in
write. If we really want to use POSIX rwlocks, I think we have to implement a reentrancy detector. (And then maybe we also want to use that for mutex, so that we can use the static initializer and the most efficient code path?)
I think the
sys::unix::rwlockimplementation is incorrect in the sense that it has undefined behavior, for two reasons:The access toThis is fixed.write_lockedis not properly synchronized: Inread, we accesswrite_lockedeven ifpthread_rwlock_rdlockfailed.write. If we really want to use POSIX rwlocks, I think we have to implement a reentrancy detector. (And then maybe we also want to use that for mutex, so that we can use the static initializer and the most efficient code path?)