Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.