Skip to content

Instantly share code, notes, and snippets.

@jpr5
Created June 27, 2010 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpr5/455046 to your computer and use it in GitHub Desktop.
Save jpr5/455046 to your computer and use it in GitHub Desktop.
require 'thread'
m = Mutex.new
m.lock
wt2 = Thread.new do
m.lock
sleep 2
m.unlock
end
# Ensure wt2 is waiting on m
sleep 0.1
wt1 = Thread.new do
m.lock
m.unlock
end
# Ensure wt1 is waiting on m
sleep 0.1
# Give it to wt2
m.unlock
wt1.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment