Created
October 2, 2014 05:47
-
-
Save mattn/59496e06a27308a73f47 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
#require 'mruby-thread' | |
m = Mutex.new | |
v = "foo" | |
th = Thread.new(v, m) do |v, m| | |
for num in 1..3 do | |
m.synchronize do | |
print("thread: num = ", num, "\n") | |
m.unlock | |
end | |
Thread.sleep 1 | |
end | |
nil | |
end | |
for num in 1..3 do | |
m.synchronize do | |
print("main: num = ", num, "\n") | |
end | |
Thread.sleep 1 | |
end | |
th.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment