Skip to content

Instantly share code, notes, and snippets.

@TJC
Created October 17, 2018 06:22
Show Gist options
  • Select an option

  • Save TJC/9149ded46e2b760fe3abfcd3cae73751 to your computer and use it in GitHub Desktop.

Select an option

Save TJC/9149ded46e2b760fe3abfcd3cae73751 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Tested on Ruby 2.5.1
require 'mini_racer'
MiniRacer::Platform.set_flags!
$iso = MiniRacer::Isolate.new
# Some mindless JS to keep the runtime busy for a moment
MY_JS = <<~JS
var foo = [];
for (i=0; i<1000; i++) {
foo[i] = 1;
foo[i] ++;
}
JS
# Make many contexts, exercise them, then dispose of them.
def many_contexts
20.times {
ctx = MiniRacer::Context.new(isolate: $iso)
ctx.eval(MY_JS)
}
end
def deadlocker
threads = []
20.times { |n|
threads << Thread.new {
GC.start(full_mark: true, immediate_sweep: true)
GC.disable
}
threads << Thread.new {
many_contexts
}
threads.each { |t| t.join }
threads = []
puts("still alive!")
}
end
deadlocker
puts("Reached end of script successfully!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment