Last active
April 26, 2016 15:49
-
-
Save Hexa/2b0e76fb7d94b59224a0a442d6b560e0 to your computer and use it in GitHub Desktop.
channel
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
j = 0 | |
SIZE = 10000 | |
a = Deque(Int32).new(SIZE) | |
#a = [] of Int32 | |
in_channel = Channel(String).new | |
out_channel = Channel(String).new | |
spawn do | |
loop do | |
receive = in_channel.receive | |
puts "in: #{receive}" | |
spawn do | |
a << j | |
j += 1 | |
out_channel.send("out: #{receive}") | |
end | |
end | |
end | |
SIZE.times do |i| | |
spawn do | |
in_channel.send("msg-#{i}") | |
end | |
end | |
SIZE.times do | |
puts out_channel.receive | |
end | |
puts j | |
puts a.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment