Created
July 20, 2013 14:20
-
-
Save slawosz/6045206 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
threads = [] | |
3.times do |i| | |
threads << Thread.new do | |
3.times do |j| | |
puts "Thread #{i} says #{j} (#{Thread.current})" | |
sleep 0.1 | |
end | |
end | |
end | |
10.times do |i| | |
puts "Lets let other threads finish #{i + 1}" | |
sleep 0.1 | |
end | |
# Result | |
# Thread 0 says 0 (#<Thread:0x007fb149954708>) | |
# Thread 1 says 0 (#<Thread:0x007fb1499545f0>) | |
# Lets let other threads finish 1 | |
# Thread 2 says 0 (#<Thread:0x007fb14982bac0>) | |
# Thread 1 says 1 (#<Thread:0x007fb1499545f0>)Thread 0 says 1 (#<Thread:0x007fb149954708>) | |
# Thread 2 says 1 (#<Thread:0x007fb14982bac0>) | |
# Lets let other threads finish 2 | |
# | |
# Lets let other threads finish 3 | |
# Thread 0 says 2 (#<Thread:0x007fb149954708>) | |
# Thread 1 says 2 (#<Thread:0x007fb1499545f0>) | |
# Thread 2 says 2 (#<Thread:0x007fb14982bac0>) | |
# Lets let other threads finish 4 | |
# Lets let other threads finish 5 | |
# Lets let other threads finish 6 | |
# Lets let other threads finish 7 | |
# Lets let other threads finish 8 | |
# Lets let other threads finish 9 | |
# Lets let other threads finish 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment