Skip to content

Instantly share code, notes, and snippets.

@mattn
Created October 2, 2014 05:47
Show Gist options
  • Save mattn/59496e06a27308a73f47 to your computer and use it in GitHub Desktop.
Save mattn/59496e06a27308a73f47 to your computer and use it in GitHub Desktop.
#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