What is the difference b/w PRLock
and PRRWLock
provided by nspr library ?

- 22,942
- 29
- 114
- 186
2 Answers
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.

- 24,871
- 19
- 102
- 158
-
+1; looking at the source they use `pthread_rwlock_rdlock/pthread_rwlock_wrlock` to implement it if PThreads are available. – CharlesB Jun 14 '11 at 14:50
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.

- 63,008
- 17
- 141
- 172