Skip to content

Interlocked.CompareExchange missing for uint, ulong and (if possible) general structs. #24694

@jkotas

Description

@jkotas

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions