Reading the Julia manual, I see that there is a “mild” deprecation for a series of atomic-related functions, including Threads.atomic_cas!. I understand this is in favor of the @atomic macro, which is apparently more granular. However, at least from a user perspective, this opens a number of issues:
-
All
@atomicoperations I have seen do not seem to reproduce the behavior ofThreads.atomic_cas!, so I am left with the doubt if there is way to replace this function; -
The
ordersymbol in the@atomicmacro is very poorly documented. The manual refers to the Julia Atomics Manifesto, which however does not describe theorder, but points to yet another document which however is for Rust. From a user perspective this is really confusing (especially if one is not fluent in Rust…). -
I wanted to use
Threads.atomic_cas!to implement a sort of soft lock. Essentially, concurrent threads would check if a shared resource (a block of memory) is free. If it is, they would use it (with a lock); if not, they would perform a slower calculation re-allocating locally the same resource. To check how this is implemented in the Julia code, I browsed thetrylock(::Threads.SpinLock)method, and saw this:function trylock(l::SpinLock) if l.owned == 0 GC.disable_finalizers() p = @atomicswap :acquire l.owned = 1 if p == 0 return true end GC.enable_finalizers() end return false endI am not sure the schema used here is totally equivalent to
Threads.atomic_cas!, since in principle one could have a concurrent thread acquiring the lock just after theif l.owned == 0line (and before thep = @atomicswapone). In other words: is thetrylockfunction really doing what it promises or should one rather use theThreads.atomic_cas!function?
Thank you