开发者

Are Reference Assignments Truly Atomic - Even On a 64 Bit Machine?

开发者 https://www.devze.com 2023-01-13 07:40 出处:网络
Just wondered if the above is true or whether reference assignments are split into two operations Is this the reason you need to use Interlocked.Exchange?

Just wondered if the above is true or whether reference assignments are split into two operations

Is this the reason you need to use Interlocked.Exchange?

Can anyone confirm?

I am talking about pointer assignment here - Is t开发者_StackOverflow社区hat truly atomic?


It depends on the type. For example Int64 assignments are not atomic in x86 mode and atomic in x64 mode. Assigning a string is atomic as it is a reference type and you are assigning a pointer and the size of the pointer is either 4 or 8 bytes depending on whether you are running on x86 or x64 bit mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消