Guest User

Untitled

a guest
Oct 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # Tested on Ruby 2.5.1
  3. require 'mini_racer'
  4.  
  5. MiniRacer::Platform.set_flags!
  6. $iso = MiniRacer::Isolate.new
  7.  
  8. # Some mindless JS to keep the runtime busy for a moment
  9. MY_JS = <<~JS
  10. var foo = [];
  11. for (i=0; i<1000; i++) {
  12. foo[i] = 1;
  13. foo[i] ++;
  14. }
  15. JS
  16.  
  17. # Make many contexts, exercise them, then dispose of them.
  18. def many_contexts
  19. 20.times {
  20. ctx = MiniRacer::Context.new(isolate: $iso)
  21. ctx.eval(MY_JS)
  22. }
  23. end
  24.  
  25. def deadlocker
  26. threads = []
  27. 20.times { |n|
  28. threads << Thread.new {
  29. GC.start(full_mark: true, immediate_sweep: true)
  30. GC.disable
  31. }
  32.  
  33. threads << Thread.new {
  34. many_contexts
  35. }
  36.  
  37. threads.each { |t| t.join }
  38. threads = []
  39. puts("still alive!")
  40. }
  41. end
  42.  
  43. deadlocker
  44. puts("Reached end of script successfully!")
Add Comment
Please, Sign In to add comment