Do semaphores prevent instruction reordering?

前端 未结 3 1495
栀梦
栀梦 2021-01-13 05:00

I was looking for an awaitable equivalent of lock statements in C#. Some people suggest using a binary SemaphoreSlim in the following way:

await         


        
3条回答
  •  一个人的身影
    2021-01-13 05:07

    SemaphoreSlim, and pretty much all of the other synchronization constructs, are built using a Monitor (or other types that are built on top of a Monitor) internally, which is exactly how a lock is implemented, giving you the same guarantees.

提交回复
热议问题