[ruby-core:68180] Re: [Ruby trunk - Bug #10867] [Feedback] An ATOMIC_GET operation should be written and used.

From: Eric Wong <normalperson@...>
Date: 2015-02-19 04:38:30 UTC
List: ruby-core #68180
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 :/

In This Thread

Prev Next