Skip to content

Instantly share code, notes, and snippets.

@andrewytliu
Created April 4, 2012 02:38
Show Gist options
  • Save andrewytliu/2297345 to your computer and use it in GitHub Desktop.
Save andrewytliu/2297345 to your computer and use it in GitHub Desktop.
Mutex with fiber: segfault under 1.9.2
m = Mutex.new
i = [0]
a = Fiber.new do
t = nil
m.synchronize { t = i[0] }
Fiber.yield
m.synchronize { i[0] = t + 1 }
end
b = Fiber.new do
t = nil
m.synchronize { t = i[0] }
Fiber.yield
m.synchronize { i[0] = t + 1 }
end
p i # => [0]
a.resume
b.resume
a.resume # 1
b.resume # 1
p i # => [1] # should be [2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment