From: SASADA Koichi Date: 2012-05-14T08:55:21+09:00 Subject: Re: [C exten] Is it safe to use rb_hash_delete() without having the GVL? Hi, (2012/05/14 0:42), I単aki Baz Castillo wrote: > 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? 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 -- // SASADA Koichi at atdot dot net