Are reads and writes to properties atomic in C#?

前端 未结 6 1995
迷失自我
迷失自我 2020-12-14 17:32

Reads and writes to certain primitive types in C# such as bool and int are atomic.

(See section 5.5, \"5.5 Atomicity of variable reference

6条回答
  •  爱一瞬间的悲伤
    2020-12-14 18:20

    I would think not. Properties are essentially just methods with a bit of syntactic sugar on them to make them a little easier to work with. So by default they're no more thread-safe than a normal method call (which is to say, not thread-safe at all).

提交回复
热议问题