Created
December 12, 2011 22:57
-
-
Save evanphx/1469546 to your computer and use it in GitHub Desktop.
This file contains 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
$scratch << :con_pre | |
$con1_ready = true | |
sleep 0.5 | |
if $con1_raise | |
$con1_raise = false | |
raise "con1" | |
end | |
sleep 0.5 | |
$scratch << :con_post |
This file contains 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
start = false | |
fin = false | |
$scratch = [] | |
$con1_ready = false | |
$con1_raise = true | |
path = "path/to/content/below.rb" | |
t1_res = nil | |
t2_res = nil | |
t1 = Thread.new do | |
begin | |
require(path) | |
rescue RuntimeError | |
end | |
# This hits the bug. Because MRI removes it's internal lock from a table | |
# when the exception is raised, this #require doesn't see that t2 is | |
# in the middle of requiring the file, so this #require runs when it should | |
# not. | |
# | |
# Sometimes this raises a ThreadError also, but I'm not sure why. | |
t1_res = require(path) | |
Thread.pass until fin | |
$scratch << :t1_post | |
end | |
t2 = Thread.new do | |
Thread.pass until $con1_ready | |
begin | |
t2_res = require(path) | |
$scratch << :t2_post | |
ensure | |
fin = true | |
end | |
end | |
t1.join | |
t2.join | |
raise "bug" unless t1_res == false | |
raise "bug" unless t2_res == true | |
$scratch == [:con_pre, :con_pre, :con_post, :t2_post, :t1_post] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment