ruby-concurrency/concurrent-ruby — pull request #145 by alexdowad (2014-08-09 14:54:45+00:00)
Title: Volatile semantics for atomic get set

(As I wrote in the commit message:)

This patch ensures that a value `#set` on a CAtomic on one thread will
immediately be visible through `#get` on another thread. The intention is
that `Atomic#get` and `#set` should provide semantics like a Java `volatile`
variable. The whole point of storing a value in an Atomic is because it will
be shared and modified from multiple threads, so it seems wrong that `#get`
and `#set` provide no particular memory-visibility guarantees. This
patch fixes that problem.

It would be better to use a load barrier for `#get` and a store barrier for
for `#set`, but I don't know how to do that in a portable way. If maximum
performance is desired, it might be necessary to use inline assembly,
with `#if`s based on the processor architecture.

The other variants of Atomic should be patched to provide the same
guarantees. The documentation should also be amended.