How do I specify the equivalent of volatile in VB.net?

前端 未结 6 1962
误落风尘
误落风尘 2020-12-03 19:05

I\'m attempting to write a lock-free version of a call queue I use for message passing. This is not for anything serious, just to learn about threading.

I\'m relativ

6条回答
  •  遥遥无期
    2020-12-03 19:39

    Starting in .NET 4.5, they added two new methods to the BCL to simulate the volatile keyword: Volatile.Read and Volatile.Write. They should be totally equivalent to reading/writing a volatile field. You can clearly use them in VB.NET . They are better (where better == faster) than the Thread.VolatileRead/Thread.VolatileWrite because they use half fences instead of full fences.

提交回复
热议问题