-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Threading
Milestone
Description
From @redknightlois on May 18, 2017 19:47
I recently needed to use Interlocked.CompareExchange inside a function with the following form:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryClaimSlot(ref uint entryKey, int key)
{
var entryKeyValue = entryKey;
//zero keys are claimed via hash
if (entryKeyValue == 0 & key != 0)
{
entryKeyValue = Interlocked.CompareExchange(ref entryKey, key, 0);
if (entryKeyValue == 0)
{
// claimed a new slot
this.allocatedSlotCount.Increment();
return true;
}
}
return key == entryKeyValue;
}problem is that it can´t be done because the Interlocked.CompareExchange<T> requires it to be a class.
Also if anyone knows a workaround for it, I would appreciate it.
Copied from original issue: dotnet/coreclr#11723
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Threading