c++multithreadingwinapireadwritelock

Is Windows' AcquireSRWLockExclusive recursive?


I need to use read-write lock, but I would also like to be sure that the lock is recursive in both read and write mode, so that calling function that uses it on the same thread doesn't lock.

I found nothing on MSDN docs. Maybe it's hidden somewhere and I didn't find it?


Solution

  • SRWLocks are not recursive, from the docs:

    An SRW lock is the size of a pointer. The advantage is that it is fast to update the lock state. The disadvantage is that very little state information can be stored, so SRW locks cannot be acquired recursively. In addition, a thread that owns an SRW lock in shared mode cannot upgrade its ownership of the lock to exclusive mode.