Jack Kada
Jack Kada

Reputation: 25202

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

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?

Upvotes: 5

Views: 333

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038770

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.

Upvotes: 5

Related Questions