Skip to content

Instantly share code, notes, and snippets.

@wavebeem
Created November 9, 2010 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wavebeem/668574 to your computer and use it in GitHub Desktop.
Save wavebeem/668574 to your computer and use it in GitHub Desktop.
#!/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