Is this lock-free .NET queue thread safe?

后端 未结 6 940
野的像风
野的像风 2021-02-06 10:32

My question is, is the class included below for a single-reader single-writer queue class thread-safe? This kind of queue is called lock-free, even if it will block if the queue

6条回答
  •  孤城傲影
    2021-02-06 10:49

    The presence of Sleep() makes a lock-free approach totally useless. The only reason to confront the complexities of a lock-free design is the need for absolute speed and to avoid the cost of Semaphores. The use of Sleep(1) defeats that purpose totally.

提交回复
热议问题