I think you can use `rb_thread_check_ints()`.