1

What is the specified behaviour of pthread's rwlock when:

  • There are readers reading,
  • There is a writer waiting on a write lock,
  • A read lock is requested

Is the read lock granted or not? If yes, is there a way to prevent the read lock being granted until the writer has been served?

dan_waterworth
  • 6,261
  • 1
  • 30
  • 41

1 Answers1

1

This is one of the disadvantages of all the POSIX locking interfaces: the standard voluntarily leaves that sort of behavior open to allow for slackness in the implementation. If you want to write portable code you can't rely on anything of that.

This makes implementation and proofs for deadlock-free algorithms particularly tedious. This is one reason why in a recent work we investigated locks that impose stronger rules, namely a FIFO policy for lock acquire.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177