From: Eric Wong Date: 2015-02-19T04:38:30+00:00 Subject: [ruby-core:68180] Re: [Ruby trunk - Bug #10867] [Feedback] An ATOMIC_GET operation should be written and used. nobu@ruby-lang.org wrote: > Won't atomic operations using gcc's `__atomic`/`__sync` built-ins or other > platform-provided functions make such barriers? Yes, but we don't use these builtins for reading (rb_signal_buff_size, for example) For a CPU memory barrier, I've used a no-op "+ 0" to read a counter: __sync_add_and_fetch(&counter, 0) If only a compiler barrier is necessary, I prefer to avoid volatile types and use something like an ACCESS_ONCE macro (similar to our RB_GC_GUARD) to cast to volatile as-needed. I really wish Ruby were GPL so it can rely on URCU for nice things :/