How are mutexes implemented?

后端 未结 6 1837
自闭症患者
自闭症患者 2020-11-30 20:35

Are some implementations better than others for specific applications? Is there anything to earn by rolling out your own?

6条回答
  •  遥遥无期
    2020-11-30 21:30

    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.

提交回复
热议问题