Am i using `AtomicReference` correctly?

to me, the usefulness of AtomicReference was never in doubt: of course it’s useful! the alternative is submitting a read operation to an actor, and waiting for that future to complete. so the fact that it is the only straightforward way to publish data that is larger than 8 bytes long without having to figure out how to implement a lock (something i thought was a bad idea, according to the other thread) or implement a custom memory allocator is enough to make it useful.

of course there is one reason why AtomicReference is not useful: it’s really hard to compile code that uses it, because of all the unsafe flags that need to be passed to make it available in the first place. i got pretty far by passing them manually from the command line, but this is not really well-supported by SPM, and they don’t seem to work with cSettings/swiftSettings in the package manifest. and packages that use unsafe flags cannot themselves be dependencies of other packages.

so it would be really helpful to me if this was enabled by default and i could depend on swift-atomics with AtomicReference as a normal package.

1 Like