Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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 that truly atomic?

like image 582
Jack Kada Avatar asked Aug 24 '10 07:08

Jack Kada


1 Answers

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.

like image 155
Darin Dimitrov Avatar answered Sep 28 '22 02:09

Darin Dimitrov