Created
November 9, 2010 01:25
-
-
Save wavebeem/668574 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
#!/usr/bin/ruby | |
# | |
# Allow the user to query the status of several running totals via multiple | |
# background threads | |
code = lambda do | |
Thread.current[:x] = 0 | |
loop do | |
Thread.current[:x] += 1 | |
Thread.pass | |
end | |
end | |
a, b, c = (1..3).map{Thread.new(&code)} | |
loop do | |
begin | |
print "a, b, c = #{[a, b, c].map{|x| x[:x]}.join(", ")}\r" | |
Thread.pass | |
rescue Interrupt | |
puts | |
exit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment