Guest User

Untitled

a guest
Jun 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. #
  3. # Allow the user to query the status of several running totals via multiple
  4. # background threads
  5.  
  6. code = lambda do
  7. Thread.current[:x] = 0
  8. loop do
  9. Thread.current[:x] += 1
  10. Thread.pass
  11. end
  12. end
  13.  
  14. a, b, c = (1..3).map{Thread.new(&code)}
  15.  
  16. loop do
  17. begin
  18. print "a, b, c = #{[a, b, c].map{|x| x[:x]}.join(", ")}\r"
  19. Thread.pass
  20. rescue Interrupt
  21. puts
  22. exit
  23. end
  24. end
Add Comment
Please, Sign In to add comment