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
···
On Sun, Jun 10, 2012 at 11:51 AM, Bartosz Dziewoński <matma.rex@gmail.com> 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.)
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.
Kind regards
robert
···
On Sun, Jun 10, 2012 at 7:52 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
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.
Thanks a lot.
···
2012/6/11 Robert Klemme <shortcutter@googlemail.com>:
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.
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 Mon, Jun 11, 2012 at 1:00 AM, Iñaki Baz Castillo <ibc@aliax.net> 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
Well, since I'm coding a C extension for Ruby 1.9 MRI, I assume I can
rely on the GVL
···
2012/6/11 Tony Arcieri <tony.arcieri@gmail.com>:
On Mon, Jun 11, 2012 at 1:00 AM, Iñaki Baz Castillo <ibc@aliax.net> 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)