Synchronization primitives and BURST (lock, mutex, atomics etc.)

Hi,

It seems that Burst currently does not support any of these. Are there any plans to add such support in the future?

Thanks

Interlocked class is supported (used by NativeHashMap) e.g. Interlocked.Exchange, Interlocked.CompareExchange

Thanks @mike_acton . I have implemented atomic adds on floats using CAS:

        public static float AtomicAdd(ref float location1, float value)
        {
            float newCurrentValue = location1; // non-volatile read, so may be stale
            while (true)
            {
                float currentValue = newCurrentValue;
                float newValue = currentValue + value;
                newCurrentValue = Interlocked.CompareExchange(ref location1, newValue, currentValue);
                if (newCurrentValue == currentValue)
                    return newValue;
            }
        }

However, I am getting:

The argument type `System.Single` for the method `CompareExchange` is not supported by burst

Unfortunately, Interlocked atomics on floats are currently not supported by burst

Does this mean you are planning to support this in the future?

There is no plan yet. This particular function is annoying because there is no existing HW intrinsics handling this, so we would need to emulate it.

1 Like

I see. Thanks for informing us.