2

When I use lock(){...}, I cannot garantee which thread will enter the lock first.

What about ReaderWriterLock? Does it works like a FIFO for the writers or not?

Marcus
  • 113
  • 1
  • 7

1 Answers1

3

What about ReaderWriterLock? Does it works like a FIFO for the writers or not?

It does.

And you pay a performance penalty for this, which is why ReaderWriterLockSlim was introduced—less overhead but it isn't "fair".

Richard
  • 106,783
  • 21
  • 203
  • 265
  • So ReaderWriterLock does the FIFO, but ReaderWriterLockSlim does not!? – Marcus Aug 11 '10 at 16:09
  • Correct. the `RaaderWriterLock` documentation covers the details (when a writer leaves all pending readers get in, when they have all completed then the longest waiting writer gets in, ...). – Richard Aug 12 '10 at 08:50