From: "Iñaki Baz Castillo" Date: 2012-04-17T19:29:57+09:00 Subject: Re: GVL lock and unlock 2012/4/17 Iñaki Baz Castillo : > So how should I fill the above GVL functions? > I use Ruby 1.9.3. I expected that GVL_UNLOCK_BEGIN/END [*] could work > but they are not defined in any .h file but in thread.c. > > Any tip please? Thanks a lot. > > > BTW: During the libuv event loop, Ruby callbacks will be called. > Should I take the GVL before invoking them? It seems I should use: /* * rb_thread_blocking_region - permit concurrent/parallel execution. * * This function does: * (1) release GVL. * Other Ruby threads may run in parallel. * (2) call func with data1. * (3) acquire GVL. * Other Ruby threads can not run in parallel any more. * * If another thread interrupts this thread (Thread#kill, signal delivery, * VM-shutdown request, and so on), `ubf()' is called (`ubf()' means * "un-blocking function"). `ubf()' should interrupt `func()' execution. * * There are built-in ubfs and you can specify these ubfs. * However, we can not guarantee our built-in ubfs interrupt * your `func()' correctly. Be careful to use rb_thread_blocking_region(). * * * RUBY_UBF_IO: ubf for IO operation * * RUBY_UBF_PROCESS: ubf for process operation * * NOTE: You can not execute most of Ruby C API and touch Ruby * objects in `func()' and `ubf()', including raising an * exception, because current thread doesn't acquire GVL * (cause synchronization problem). If you need to do it, * read source code of C APIs and confirm by yourself. * * NOTE: In short, this API is difficult to use safely. I recommend you * use other ways if you have. We lack experiences to use this API. * Please report your problem related on it. * * Safe C API: * * rb_thread_interrupted() - check interrupt flag * * ruby_xalloc(), ruby_xrealloc(), ruby_xfree() - * if they called without GVL, acquire GVL automatically. */ -- Iñaki Baz Castillo