I'm using Crystal bindings for X11 and typical usage looks something like this:
loop do
event = display.next_event # <- blocking!
# do stuff with event
end
This works fine but I can't do anything in parallel now because next_event
is native C code and thus never yields.
xlib's NextEvent is always blocking, also in C. There's a thread about it with possible alternatives, but polling is slower and more CPU demanding than next_event
, so I'd like to stick to that blocking call. Do I have to put this into its separate OS thread? -Dpreview_mt
actually solves this, but that's an experimental flag and makes all concurrency threaded which is unnecessary (edit: Just found out, this is not true, there is spawn same_thread: true do
syntax). What options do I have?
Edit: I just found this is discussed in more detail in this thread which is worth reading on the topic. There's also FileDescriptor
's wait_readable
which can resolve this if you can obtain a FD somehow.