Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Concorrência, paralelismo e o Ruby

Ricardo Valeriano
March 09, 2013
550

Concorrência, paralelismo e o Ruby

GuruSP 09/03/

Ricardo Valeriano

March 09, 2013
Tweet

More Decks by Ricardo Valeriano

Transcript

  1. IO?

  2. IO?

  3. IO?

  4. IO?

  5. IO?

  6. IO?

  7. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end
  8. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end
  9. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new
  10. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new (1..100).map do Thread.new{ } end
  11. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new (1..100).map do Thread.new{ } end 100.times { omg.pluzz(1) }
  12. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new (1..100).map do Thread.new{ } end 100.times { omg.pluzz(1) } .each(&:join)
  13. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new
  14. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new
  15. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new omg.pluzz 1
  16. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter omg.pluzz 1
  17. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 omg.pluzz 1
  18. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 omg.pluzz 1
  19. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 omg.pluzz 1
  20. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1
  21. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1
  22. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2
  23. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2
  24. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2
  25. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2
  26. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2
  27. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2
  28. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2
  29. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2
  30. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2 @counter 2 2 + 1 @counter= 3
  31. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2 @counter 2 2 + 1 @counter= 3
  32. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2 @counter 2 2 + 1 @counter= 3
  33. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2 2 + 1 @counter 2 2 + 1 @counter= 3
  34. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2 2 + 1 @counter= 3 @counter 2 2 + 1 @counter= 3
  35. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new @counter 0 0 + 1 @counter=1 @counter 1 1 + 1 @counter= 2 @counter 2 2 + 1 @counter= 3 @counter 2 2 + 1 @counter= 3
  36. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end require 'monitor'
  37. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end require 'monitor' include MonitorMixin
  38. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end require 'monitor' include MonitorMixin super
  39. class SomatorOMG attr_accessor :counter def initialize @counter = 0 end

    def pluzz(how_much) @counter = @counter + how_much end end require 'monitor' include MonitorMixin synchronize do end super
  40. require "net/http" threads = (1..4).map { Thread.new { html =

    Net::HTTP.get( URI("http://localhost:4567/go")) puts html } } puts "foi-se-se" threads.each &:join
  41. require "net/http" threads = (1..4).map { Thread.new { html =

    Net::HTTP.get( URI("http://localhost:4567/go")) puts html } } puts "foi-se-se" threads.each &:join
  42. require "net/http" threads = (1..4).map { Thread.new { html =

    Net::HTTP.get( URI("http://localhost:4567/go")) puts html } } puts "foi-se-se" threads.each &:join
  43. require "net/http" threads = (1..4).map { Thread.new { html =

    Net::HTTP.get( URI("http://localhost:4567/go")) puts html } } puts "foi-se-se" threads.each &:join
  44. require "net/http" threads = (1..4).map { Thread.new { html =

    Net::HTTP.get( URI("http://localhost:4567/go")) puts html } } puts "foi-se-se" threads.each &:join
  45. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  46. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  47. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  48. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  49. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  50. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  51. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  52. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  53. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  54. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  55. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  56. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  57. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  58. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  59. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  60. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  61. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  62. google_callback = Fiber.new do |html| t = Thread.new { html

    = Net::HTTP.get(URI("http://google.com")) } puts "fui, vou sair da fiber" Fiber.yield t.join puts "OMG! Voltei para fiber" puts html puts "fiber done" end puts "startando a fiber" google_callback.resume puts "vamos aguardar a Fiber?" 5.times { sleep(1) puts "ainda nao" } puts "vamos voltar deliberadamente para a Fiber" google_callback.resume puts "script done"
  63. #!/usr/bin/env ruby # # server_1 require 'eventmachine' module EchoServer def

    post_init puts "-- someone connected to the echo server!" end def receive_data data send_data ">>> you sent: #{data}" end end EventMachine::run { EventMachine::start_server "127.0.0.1", 8081, EchoServer puts 'running echo server on 8081' }
  64. #!/usr/bin/env ruby # # server_1 require 'eventmachine' module EchoServer def

    post_init puts "-- someone connected to the echo server!" end def receive_data data send_data ">>> you sent: #{data}" end end EventMachine::run { EventMachine::start_server "127.0.0.1", 8081, EchoServer puts 'running echo server on 8081' }
  65. #!/usr/bin/env ruby require 'eventmachine' class Echo < EventMachine::Connection def post_init

    send_data 'Hello' end def receive_data(data) p data end end EventMachine.run { EventMachine.connect '127.0.0.1', 8081, Echo }
  66. #!/usr/bin/env ruby require 'eventmachine' class Echo < EventMachine::Connection def post_init

    send_data 'Hello' end def receive_data(data) p data end end EventMachine.run { EventMachine.connect '127.0.0.1', 8081, Echo }
  67. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end
  68. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end
  69. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  70. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  71. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  72. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  73. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  74. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  75. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  76. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  77. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  78. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  79. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  80. def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get http.callback {

    f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" if page page = http_get('http://www.google.com/') puts "Fetched: #{page.response_header.status}" end }.resume end Loop de Eventos
  81. do puts "OMG! Nasci!" end pid = Process.fork puts "#{pid},

    eu (#{Process.pid}) sou seu pai! XD"
  82. do puts "OMG! Nasci!" end pid = Process.fork while true

    sleep(1) end puts "#{pid}, eu (#{Process.pid}) sou seu pai! XD"
  83. do puts "OMG! Nasci!" end pid = Process.fork while true

    sleep(1) end while true sleep(1) end puts "#{pid}, eu (#{Process.pid}) sou seu pai! XD"
  84. rupy = "Rupy BR" Process.fork do end rupy << "

    2012" puts "no filho: #{rupy}"
  85. rupy = "Rupy BR" Process.fork do end rupy << "

    2012" puts "no filho: #{rupy}" puts "no pai: #{rupy}"
  86. rupy = "Rupy BR" Process.fork do end rupy << "

    2012" puts "no filho: #{rupy}" puts "no pai: #{rupy}"
  87. rupy = "Rupy BR" Process.fork do end rupy << "

    2012" puts "no filho: #{rupy}" puts "no pai: #{rupy}"
  88. rupy = "Rupy BR" Process.fork do end rupy << "

    2012" puts "no filho: #{rupy}" puts "no pai: #{rupy}"
  89. rupy = "Rupy BR" Process.fork do end rupy << "

    2012" puts "no filho: #{rupy}" puts "no pai: #{rupy}"
  90. pid = Process.fork do end reader, writer = IO.pipe while(

    (msg = gets.chomp) != "fui") writer.puts "Papa: #{msg}" end
  91. pid = Process.fork do end reader, writer = IO.pipe while(

    (msg = gets.chomp) != "fui") writer.puts "Papa: #{msg}" end puts "fui papa!"
  92. pid = Process.fork do end reader, writer = IO.pipe while(

    (msg = gets.chomp) != "fui") writer.puts "Papa: #{msg}" end puts "fui papa!" while(msg = reader.gets) puts msg end
  93. pid = Process.fork do end reader, writer = IO.pipe while(

    (msg = gets.chomp) != "fui") writer.puts "Papa: #{msg}" end puts "fui papa!" while(msg = reader.gets) puts msg end writer.close
  94. pid = Process.fork do end reader, writer = IO.pipe while(

    (msg = gets.chomp) != "fui") writer.puts "Papa: #{msg}" end reader.close puts "fui papa!" while(msg = reader.gets) puts msg end writer.close
  95. reader, writer = IO.pipe pid = Process.fork do end armenga

    = Armenga.new armenga.lol = "LoLoLoLing" writer.puts Marshal::dump armenga
  96. reader, writer = IO.pipe pid = Process.fork do end armenga

    = Armenga.new armenga.lol = "LoLoLoLing" writer.puts Marshal::dump armenga reader.close
  97. reader, writer = IO.pipe writer.close data = reader.gets omg =

    Marshal::load data pid = Process.fork do end armenga = Armenga.new armenga.lol = "LoLoLoLing" writer.puts Marshal::dump armenga reader.close
  98. reader, writer = IO.pipe writer.close data = reader.gets omg =

    Marshal::load data pid = Process.fork do end armenga = Armenga.new armenga.lol = "LoLoLoLing" writer.puts Marshal::dump armenga reader.close puts omg.lol puts omg.sera?
  99. >> future = charlie.future.report => #<Celluloid::Future:0x000001009759b8> >> future.value => "Charlie

    Sheen is winning!" class Charlie def report # some sloooooow process here. end end
  100. >> future = charlie.future.report => #<Celluloid::Future:0x000001009759b8> >> future.value => "Charlie

    Sheen is winning!" class Charlie def report # some sloooooow process here. end end include Celluloid
  101. You don't have to choose between threaded and evented IO!

    Celluloid::IO is ideal for servers which handle large numbers of mostly-idle connections.