I'm implementing a simple windowing library as a Ruby C extension. Windows have a handle_events!
method that enters their native event loop.
The problem is that I want one event loop per window and the method blocks. I'd like the method to return immediately and let the loop run in a separate thread. What would be the best way to achieve this?
I tried using rb_thread_call_without_gvl
to call the event loop function, and then use rb_thread_call_with_gvl
in order to call the window's callbacks, which are Proc
s. Full source code can be found here.
It still works, but not as I intended: the method still blocks. Is this even possible with Ruby's threading model?