Skip to content

Instantly share code, notes, and snippets.

@nahi
Created December 19, 2011 05:01
Show Gist options
  • Save nahi/1495459 to your computer and use it in GitHub Desktop.
Save nahi/1495459 to your computer and use it in GitHub Desktop.
class Foo
def initialize
@var = 0
@updated = false
end
def update
@updated = true
@var = 42
end
def check
x = @updated
raise if @var == 42 && !x
@updated
end
end
100.times do
obj = Foo.new
t1 = Thread.new {
sleep 0.01
obj.update
}
100.times.map {
Thread.new {
Thread.pass while !obj.check
}
}.each(&:join)
t1.join
end
@nahi
Copy link
Author

nahi commented Dec 19, 2011

!!CAUTION!! This test has a concurrency bug... '@Updated = true' can be executed by another Thread just after 'x = @Updated' is executed. I cannot emulate volatility issue in JRuby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment