Are some implementations better than others for specific applications? Is there anything to earn by rolling out your own?
I used Reflector.NET to decompile the source for System.Threading.ReaderWriterLockSlim
, which was added to a recent version of the .NET framework.
It mostly uses Interlocked.CompareExchange
, Thread.SpinWait
and Thread.Sleep
to achieve synchronisation. There are a few EventWaitHandle
(kernel object) instances that are used under some circumstances.
There's also some complexity added to support reentrancy on a single thread.
If you're interested in this area and working in .NET (or at least, can read it) then you might find it quite interesting to check this class out.