Created
August 13, 2020 09:29
-
-
Save rofr/96a065faaff3383e67a58b96d7adf1fb to your computer and use it in GitHub Desktop.
Is object assignment in .NET atomic?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AtomicAssignment | |
{ | |
static object o; | |
static AtomicAssignment() => o = new object(); | |
public static Update() | |
{ | |
//is the assignment atomic? or is something like Interlocked.Exchange necessary? | |
o = new object(); | |
} | |
public static Read() | |
{ | |
//if the assignment in Update() is atomic then this should be thread safe | |
//we will get a valid reference to an object | |
object refCopy = o; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment