From: "Iñaki Baz Castillo" Date: 2012-05-01T02:37:42+09:00 Subject: Re: What is the meaning of rb_thread_interrupted() ? 2012/4/30 Iñaki Baz Castillo : > The exact code is here: > >  https://github.com/ibc/AsyncEngine/blob/master/ext/asyncengine/asyncengine_ruby.c#L61 > > > As said before, it works "perfectly" (no issues found for now), but in > case I add (for example) a periodic timer to be executed every 1 > miliseconds by UV, then such a callback is executed every 1 > milisecond, which involves calling to > "rb_thread_call_with_gvl(rb_thread_check_ints, NULL);". > Maybe it is not efficient and I could check in some other way whether > there are received signals before calling to rb_thread_check_ints() ? > > Initially I figured out that rb_thread_interrupted() (which can be > called safely in the blocking region) would be what I'm looking for, > but I think it's not (since it just does not work). I found rb_signal_buff_size() which seems to return the number of pending signals to handle. I thought that it could help in this way: static void prepare_cb(uv_prepare_t* handle, int status) { // Check received interruptions in Ruby land. if (rb_signal_buff_size()) rb_thread_call_with_gvl(rb_thread_check_ints, NULL); ...but it does not because: 1) The process needs to receive two signals instead of one. 2) It does not improve efficience at all (in my benchmarks). So maybe I should keep the working solution I already have? Thanks. -- Iñaki Baz Castillo