Created
September 22, 2020 15:26
-
-
Save smailliwcs/345dbc6f0b69b375f1ecef330734464d to your computer and use it in GitHub Desktop.
Interlocked Booleans
This file contains 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
using System; | |
using System.Threading; | |
public class InterlockedBoolean | |
{ | |
private int value; | |
public bool Value | |
{ | |
get { return Convert.ToBoolean(value); } | |
} | |
public InterlockedBoolean(bool value) | |
{ | |
this.value = Convert.ToInt32(value); | |
} | |
public bool Exchange(bool value) | |
{ | |
return Convert.ToBoolean(Interlocked.Exchange(ref this.value, Convert.ToInt32(value))); | |
} | |
public bool CompareExchange(bool value, bool comparand) | |
{ | |
return Convert.ToBoolean(Interlocked.CompareExchange(ref this.value, Convert.ToInt32(value), Convert.ToInt32(comparand))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment