Created
January 29, 2013 16:50
-
-
Save sw17ch/4665730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'thread' | |
$id = 0 | |
$sem = Mutex.new | |
def next_id | |
n = nil | |
$sem.synchronize do | |
n = $id | |
$id += 1 | |
end | |
return n | |
end | |
a = Thread.new do | |
100.times do | |
puts "A: #{next_id}" | |
end | |
end | |
b = Thread.new do | |
100.times do | |
puts "B: #{next_id}" | |
end | |
end | |
a.run | |
b.run | |
a.join | |
b.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Subsection of af ull run: