ruby-concurrency/atomic

Document what "memory model" guarantees each Atomic method provides

alexdowad opened this issue · 3 comments

From reading the source, it appears that #compare_and_set, #update, and #try_update are all equivalent to a full memory barrier. It also appears that #get, #set, and #swap provide no concurrency guarantees whatsoever.

This is crucial information when using Atomic to write correct, high-performance, concurrent code. It should be included right in the RDoc for each method, and also mentioned in the README.

Closing because this gem has been deprecated.

I'll try to answer the question even though future discussion should move to concurrent-ruby.

In the JRuby code, Atomic always uses a volatile field. That will represent a memory barrier for both set and get, as in the JDK's AtomicReference class.

I'm not as familiar with the C code.