Is this lock-free .NET queue thread safe?

后端 未结 6 952
野的像风
野的像风 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 11:07

    Given that I can't find any reference that the Interlocked.Exchange does Read or Write blocks, I would say not. I would also question why you want to go lockless, as seldom gives enough benefits to counter it's complexity.

    Microsoft had an excellent presentation at the 2009 GDC on this, and you can get the slides here.

提交回复
热议问题