Created
November 30, 2018 20:06
-
-
Save havenwood/c06744c8de4a206f86492d3d5e7b765b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fiddle/import' | |
module GVLUnlock | |
extend ::Fiddle::Importer | |
dlload ::Fiddle::Handle::DEFAULT | |
FP = | |
bind 'void *cb(void *data)' do |ptr| | |
ptr.to_i << 1 | |
end | |
extern 'void * rb_thread_call_without_gvl(void *(*func)(void *data), void *data1, | |
rb_unblock_function_t *ubf, void *data2)' | |
def self.run fp | |
rb_thread_call_without_gvl(FP, 0, 0, 0).to_value | |
end | |
end | |
def foo | |
10.times { puts ":)" } | |
end | |
p GVLUnlock.run foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment