Last active
May 14, 2019 12:58
-
-
Save deepumi/b44ee1b356adbc2d00174a973dadff8a to your computer and use it in GitHub Desktop.
Thready safety in Static Variables
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
| //Interlocked class Provides atomic operations for variables that are shared by multiple threads. | |
| private static string _data; | |
| public ActionResult Index() | |
| { | |
| //Compares two instances of the specified reference type <paramref name="T" /> for equality and, if they are equal, replaces the first one | |
| if (Interlocked.CompareExchange(ref _data, "test", null) == null) | |
| { | |
| } | |
| .... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment