It is atomic on MRI. It may or may not be on other interpreters, if
you care about them. (But probably should be as an element of the
syntax.)
Array#<< may or may not be atomic as well. (It is on MRI.)
Thanks, so I’ve no problem since I’m coding for MRI.
Sorry, but I think this is the wrong attitude. Even MRI’s
implementation can change and the default should be to properly
synchronize access to shared resources - if only for documenting the
shared access. Note also that multiple threads may invoke #method2
which makes synchronization necessary even in absence of swapping.
Sorry, but I think this is the wrong attitude. Even MRI’s
implementation can change and the default should be to properly
synchronize access to shared resources - if only for documenting the
shared access. Note also that multiple threads may invoke #method2
which makes synchronization necessary even in absence of swapping.
In my case #method2 is private and is just called by the library and
always in the same thread (the thread in which a C event loop runs).
I do agree that, while in Ruby land, I should use a mutex (not
required right now since Array#<< and a,b=c,d are atomic, but this
could change). However I’m re-writing my #method1 and #method2 in C
so, for sure I don’t need mutex. Please correct me if I’m wrong.
On Mon, Jun 11, 2012 at 1:00 AM, Iñaki Baz C. [email protected] wrote:
I do agree that, while in Ruby land, I should use a mutex (not
required right now since Array#<< and a,b=c,d are atomic
Note that Array#<< isn’t atomic, it’s just that the GIL prevents contention
between threads so it never becomes a problem (until you try to use a Ruby
implementation without a GIL)
Well, since I’m coding a C extension for Ruby 1.9 MRI, I assume I can
rely on the GVL
On Mon, Jun 11, 2012 at 1:00 AM, Iaki Baz C. [email protected]
wrote:
I do agree that, while in Ruby land, I should use a mutex (not
required right now since Array#<< and a,b=c,d are atomic
Note that Array#<< isn’t atomic, it’s just that the GIL prevents
contention
between threads so it never becomes a problem (until you try to use a
Ruby
implementation without a GIL)
On Sun, Jun 10, 2012 at 11:51 AM, Bartosz Dziewoński [email protected] wrote:
It is atomic on MRI. It may or may not be on other interpreters, if
you care about them. (But probably should be as an element of the
syntax.)
I would not bet on it being atomic, since Ruby’s context-switch
boundaries are not formally defined. However, atomicity is only
important if you expect that a non-atomic assignment would produce
different results than an atomic one, which is unlikely in this case.
Of course, if it matters, you shouldn’t rely on this being atomic.
Charlie
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.