Created
October 17, 2018 06:22
-
-
Save TJC/9149ded46e2b760fe3abfcd3cae73751 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 | |
| # 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