You can fake it with Interlocked.CompareExchange(ref int, int, int)
in a loop, but I don't think it would be more efficient:
private static void SetBit(ref int valueToUpdate, int bitToSet)
{
while (true)
{
int oldValue = valueToUpdate;
int newValue = oldValue | bitToSet;
int result = Interlocked.CompareExchange(ref valueToUpdate, newValue, oldValue);
if (result == oldValue) break;
}
}