Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/ffi_c/Function.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ async_cb_dispatcher_initialize(struct async_cb_dispatcher *ctx)

/* Name thread, for better debugging */
rb_funcall(ctx->thread, rb_intern("name="), 1, rb_str_new2("FFI Callback Dispatcher"));
/* Advise multi-threaded app servers to ignore this thread for the purposes of fork safety warnings */
rb_funcall(ctx->thread, rb_intern("thread_variable_set"), 2, ID2SYM(rb_intern("fork_safe")), Qtrue);
}

static struct async_cb_dispatcher *
Expand Down
4 changes: 3 additions & 1 deletion spec/ffi/function_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ module LibTest
skip 'this is MRI-specific' if RUBY_ENGINE == 'truffleruby' || RUBY_ENGINE == 'jruby'
FFI::Function.new(:int, []) { 5 } # Trigger initialization

expect(Thread.list.map(&:name)).to include('FFI Callback Dispatcher')
thread = Thread.list.find { |t| t.name == 'FFI Callback Dispatcher' }
expect(thread).to_not be_nil
expect(thread.thread_variable_get(:fork_safe)).to be true
end
end

Expand Down