Hi, my code is a C event loop that runs without the GVL (so other Ruby
1.9.3 threads can take the control) and when an event occurs it get
the GVL and executed a user provided Ruby block/proc.
Prior to calling rb_thread_call_with_gvl(), my code removes an element
from a Ruby hash by using rb_hash_delete(). This is, such an operation
is done from a thread which has not the GVL, so it could be dangerous.
However I get no errors at all. If I run more Ruby code without having
the GVL then of course I get critical errors, but that does not occur
if I just use rb_hash_delete().
So, is it safe to use rb_hash_delete() without having the GVL?
Thanks a lot.
Hi,
(2012/05/14 0:42), Iñaki Baz C. wrote:
So, is it safe to use rb_hash_delete() without having the GVL?
I believe it is dangerous.
Because:
(1) rb_hash_delete() can call Ruby’s #hash method for each elements.
(2) If another thread access to the hash simultaneously, it will be
crash.
Regards,
Koichi
2012/5/14 SASADA Koichi [email protected]:
I believe it is dangerous.
Because:
(1) rb_hash_delete() can call Ruby’s #hash method for each elements.
(2) If another thread access to the hash simultaneously, it will be crash.
Thanks, I understand. However in my case I use Fixnums as keys in the
hash. I’ve done several tests and never crashes, maybe because Fixnum
objects are “untouchable”?
2012/5/14 Peter Z. [email protected]:
Fixnum instances are immutable and calling #hash should be safe on them.
However, point 2) stands: if two threads will access the hash
simultaneously,
that may and will lead to crashes.
Thanks. I’ll try to redesign my code then.
Iñaki Baz C. писал 14.05.2012 04:32:
hash. I’ve done several tests and never crashes, maybe because Fixnum
objects are “untouchable”?
Fixnum instances are immutable and calling #hash should be safe on
them.
However, point 2) stands: if two threads will access the hash
simultaneously,
that may and will lead to crashes.