I am writing a C extension providing an interface between Ruby and an asynchronous I / O library. When I run tests on my code, I often get errors, including (but not limited to):
[BUG] cross-thread violation in rb_thread_schedule()
Asynchronous IO means that the C extension will have to deliver ruby messages from multiple threads (rather than the main interpreter thread). How to avoid these thread safety violations in the process?
ruby 1.8.x - - API Ruby/C . , ruby 1.9.x, , . , , API, / . , Ruby. ruby, ruby green select(). :
select()
rb_thread_wait_fd()
. rb_io_sysread() ( IO#sysread) , , , - ruby.
rb_io_sysread()
IO#sysread