Take the 2-minute tour ×

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

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
+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
add comment

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.

share|improve this answer
add comment

Your Answer


