Do semaphores prevent instruction reordering?
问题 I was looking for an awaitable equivalent of lock statements in C#. Some people suggest using a binary SemaphoreSlim in the following way: await semaphore.WaitAsync().ConfigureAwait(false); try { //inner instructions } finally { semaphore.Release(); } I know it has some issues (e.g. it's not reentrant), but my biggest concern is with the instruction reeordering. In plain old lock statements we have a guarantee that no inner instruction from the lock will be moved outside (before or after) the