Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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!")
Add Comment
Please, Sign In to add comment