Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Created September 22, 2020 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smailliwcs/345dbc6f0b69b375f1ecef330734464d to your computer and use it in GitHub Desktop.
Save smailliwcs/345dbc6f0b69b375f1ecef330734464d to your computer and use it in GitHub Desktop.
Interlocked Booleans
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