How to avoid cross violations in the Ruby extension?

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?

+5
source share
1 answer

ruby ​​1.8.x - - API Ruby/C . , ruby ​​1.9.x, , . , , API, / . , Ruby. ruby, ruby ​​green select(). :

  • IPC, select().
  • .
  • , rb_thread_wait_fd() . .
  • , , , .

. rb_io_sysread() ( IO#sysread) , , , - ruby.

+7

All Articles