What is the difference b/w PRLock and PRRWLock
provided by nspr library ?
What is difference b/w PRLock and PRRWLock
184 Views Asked by Vivek Goel At
2
There are 2 best solutions below
0
On
PRLock is a simple mutex. PRRWLock is an (unfortunately undocumented) reader-writer lock.
The only source of documentation I can find on PRRWLock is contained within prrwlock.h, and includes the methods one would expect for a reader-writer lock implementation:
- Create and Destroy
- Acquire Reader-lock
- Acquire Writer-lock
- Release the lock
An example of its usage is contained in rwlocktest.c. The rank of the lock is used for deadlock detection and is asserted in debug builds to ensure that a thread only acquires a lock of rank equal or greater to all currently held locks.
I don't know anything about the library but the names suggest that one is a standard lock and the other is a reader/writer lock. The first always gives exclusive access, and the second allows multiple concurrent reads but exclusive writes. For example, pthreads api has pthread_mutex_lock/pthread_mutex_unlock and pthread_rwlock_rdlock/pthread_rwlock_wrlock methods.