Skip to content

Instantly share code, notes, and snippets.

@mattn
Created March 19, 2014 03:54
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 mattn/9635198 to your computer and use it in GitHub Desktop.
Save mattn/9635198 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.lock
print("thread: num = ", num, "\n")
m.unlock
Thread.sleep 1
end
nil
end
for num in 1..3 do
m.lock
print("main: num = ", num, "\n")
m.unlock
Thread.sleep 1
end
th.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment