Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment