Skip to content

Instantly share code, notes, and snippets.

@suzukaze
Forked from mattn/sem.rb
Last active August 29, 2015 14:07
Show Gist options
  • Save suzukaze/1b43b085228aadfb77cb to your computer and use it in GitHub Desktop.
Save suzukaze/1b43b085228aadfb77cb 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