SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
Ruby
  goes to
Ruby,

        @elise_huard Rubykaigi 2011
Context
“Concurrency is hard”
“Shared and Mutable State”
“Why Bother?”
Actors
“Actor Model” (1973)
             (1973)
“No Global State”
”                          ”

            “Actors”
        ”              ”

“Partial Order of Execution”
      ”                ”
Mutable
Mutable
“Sleeping Barber”
The
                                 universe
                                          customer X
                    wake up
                    customers?
 Barber
sleeping/cutting   customer X    BarberShop
                                 customers waiting
                        no
Ruby
“Rubinius Actors”
   @mentalguy
“Revactor”
 @bascule
“Celluloid”
class Barber
  include Celluloid::Actor
  attr_accessor :status

  def initialize(shop)
    @shop = shop
  end

  def cut_customer(name)
    puts "    cutting customer #{name}"
    sleep(rand(5))              Text
    accident = rand(2)
    if accident
      puts "       finished cutting #{name}"
    else
      puts "       *** whoops, chopped #{name}'s head off ***"
    end
    shop.customer_leaves!
  end
(...)
end
class Shop
  include Celluloid::Actor

  def initialize
    @barber = Barber.new(self)
    @chairs = []
    puts "lights on ..."
  end

  def waiting_line
    @chairs.size
  end

  def new_customer(name)          Text
    puts " customer arriving: #{name}"
    if waiting_line > 3
      puts "*** sorry, #{name}, no room ***"
    else
      @chairs << name
      @barber.cut_customer!(name)
    end
  end

  def customer_leaves
    @chairs.shift
  end
end
shop = Shop.new
['jack', 'john', 'henry', 'tom', 'bob'].each
do |customer|
                    Text
  shop.new_customer!(customer)
end
shop.report
“CRuby”
Foreign lands
“Erlang”
%% shop %%
barber_shop() ->
  io:format("lights on ... ~n"),
  ShopPid = self(),
  BarberPid = spawn(fun() -> barber(ShopPid) end),
  barber_shop_in_business(BarberPid, []).

barber_shop_in_business(BarberPid, CustomersInChairs) ->
  receive
    {cut, Customer} ->
       % pop customer from list when hair is being cut
       remove_customer(BarberPid, CustomersInChairs,
Customer);
    barbercheck ->
       respond_to_barber(BarberPid, CustomersInChairs);
    Customer ->
       io:format("~p arrives~n",[Customer]),
       % should check the number of customers waiting first
       % if all full: customer turned away
       add_customer_if_available(BarberPid, CustomersInChairs,
Customer)
  end.
%% barber %%
barber(ShopPid) ->
  ShopPid ! barbercheck,
  receive
    wakeup ->
       barber(ShopPid);
    {customer, Customer} ->
       cut(ShopPid, Customer),
       barber(ShopPid)
  end.                     Text
cut(ShopPid, Name) ->
  io:format("cutting ~p~n", [Name]),
  % take customer -> can be removed from waiting chairs
  ShopPid ! {cut, Name},
  timer:sleep(random:uniform(10000)),
  io:format("finished cutting: ~p~n", [Name]).
scenario() ->
  ShopPid = start_shop(),
  % send customers to the shop
  ShopPid ! 'john',
  ShopPid ! 'joe',Text
  timer:sleep(20000),
  ShopPid ! 'kevin',
  ShopPid ! 'richard',
  main_end.
http://vimeo.com/26560141


            Text
“Elixir”
object Shop
 def initialize
  shop_pid = Process.current
  barber_pid = Process.spawn -> Barber.loop(shop_pid)
  @('barber_pid: barber_pid, 'shop_pid: shop_pid)
 end

 def loop(customers_in_chairs)
   IO.puts "shop loop #{customers_in_chairs}"
   receive
   match {'cut, customer}
     if customers_in_chairs.include?(customer)
       loop(customers_in_chairs.delete(customer))
     else                               Text
       loop(customers_in_chairs)
     end
   match 'barbercheck
     IO.puts "barber checking ..."
     respond_to_barber(customers_in_chairs)
   match {'customer, customer}
     IO.puts("new customer #{customer}")
     add_customer(customers_in_chairs, customer)
   end
 end
 (...)
end
module Barber
 def loop(shop_pid)
  shop_pid <- 'barbercheck
  receive
  match 'wakeup
   IO.puts "wakeup"
    loop(shop_pid)
  match {'customer, customer}
    cut_hair(shop_pid, customer)
    loop(shop_pid)               Text
  end
 end

 def cut_hair(shop_pid, customer)
  IO.puts "cutting customer #{customer}"
  shop_pid <- {'cut, customer}
  IO.puts "finished cutting customer #{customer}"
 end
end
pid = Process.spawn -> Shop.new.loop([])
IO.puts pid
pid <- {'customer, "jack"}
                       Text
pid <- {'customer, "bob"}
“Scala”
class BarberShop extends Actor {
  var barber: ActorRef = null
  var customersInChairs = List[Customer]()

    override def preStart() {
      barber = Actor.actorOf(new Barber(self)).start()
    }

    def receive = {
      case Customer(name) =>
        if (customersInChairs.length >= 3) {
                                Text
          println("sorry, no room for " + name)
        } else {
          customersInChairs = customersInChairs :+ Customer(name)
          barber ! WakeUp
        }
      case Cut(name) =>
        customersInChairs = customersInChairs.tail
      case BarberCheck =>
        // send first customer
        barber ! customersInChairs.head
    }
}
class Barber(val shop: ActorRef) extends Actor {
  def cut(name: String) = {
    shop ! Cut(name)
  }
  def receive = {
    case WakeUp =>
      shop ! BarberCheck
                        Text
    case Customer(name) =>
      cut(name)
      shop ! BarberCheck
  }
}
package sleepingBarber

import akka.actor.{Actor, ActorRef, ActorRegistry}
import Actor._
import akka.actor.Actor.actorOf

/* messages classes */
sealed trait BarberMessage
case class Customer(name: String) extends BarberMessage
case class Cut(name: String) extends BarberMessage
case class BarberCheck() extends BarberMessage
                               Text
case class NoCustomers() extends BarberMessage
case class WakeUp() extends BarberMessage

object SleepingBarber {
  def main(args: Array[String]) : Unit = {
    val barberShop = Actor.actorOf[BarberShop].start()
    barberShop ! Customer("John")
    barberShop ! Customer("Jack")
    barberShop ! Customer("Arthur")
    Actor.registry.shutdownAll
  }
}
“JRuby”
Caveat
“easy to understand”
    “                          ”

        “real encapsulation”
              ”     ”

    “highly decentralized”
”                                  ”
“clear separation of parallel components”
          “                           ”

      “livelocks - deadlocks still possible”
“             -                                 ”
“Concurrency Primitives”
Epilogue
“Time to control shared state?”
  shared state
“Better Concurrency Primitives
         in stdlib?”
!

  Speaker                           Pictures


                                Sherlock Jr (1924)
@elise_huard                     Safety Last (1923)
                          A Woman of Affairs (1928)
                          Mysteries of a Barbershop (1923)
Translation                       The Doll (1919)
                                 Intolerance (1926)
                                 Metropolis (1927)
                          He Who Gets Slapped (1924)
 Conference
                             Laughing Gravy (1931)
                               Documentation
Ruby Kaigi 2011
                  http://www.delicious.com/elisehuard/concurrency
  Sponsor


   Forward
The End

    @  @@elise_huard
    Translation:

Contenu connexe

Plus de ehuard

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017ehuard
 
Ruby hollywood nordic
Ruby hollywood nordicRuby hollywood nordic
Ruby hollywood nordicehuard
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywoodehuard
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, pluralehuard
 
Concurrency
ConcurrencyConcurrency
Concurrencyehuard
 
12 hours to rate a rails application
12 hours to rate a rails application12 hours to rate a rails application
12 hours to rate a rails applicationehuard
 
Barcamp Ghent2009
Barcamp Ghent2009Barcamp Ghent2009
Barcamp Ghent2009ehuard
 
Tokyo Cabinet
Tokyo CabinetTokyo Cabinet
Tokyo Cabinetehuard
 
The real-time web
The real-time webThe real-time web
The real-time webehuard
 
Rails and the internet of things
Rails and the internet of thingsRails and the internet of things
Rails and the internet of thingsehuard
 

Plus de ehuard (11)

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017
 
Ruby hollywood nordic
Ruby hollywood nordicRuby hollywood nordic
Ruby hollywood nordic
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, plural
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
12 hours to rate a rails application
12 hours to rate a rails application12 hours to rate a rails application
12 hours to rate a rails application
 
Barcamp Ghent2009
Barcamp Ghent2009Barcamp Ghent2009
Barcamp Ghent2009
 
Tokyo Cabinet
Tokyo CabinetTokyo Cabinet
Tokyo Cabinet
 
The real-time web
The real-time webThe real-time web
The real-time web
 
Rails and the internet of things
Rails and the internet of thingsRails and the internet of things
Rails and the internet of things
 
Oauth
OauthOauth
Oauth
 

Dernier

Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxsaniyaimamuddin
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCRashishs7044
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Americas Got Grants
 
Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...Peter Ward
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyotictsugar
 
Darshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfDarshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfShashank Mehta
 

Dernier (20)

Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...
 
Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...Fordham -How effective decision-making is within the IT department - Analysis...
Fordham -How effective decision-making is within the IT department - Analysis...
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyot
 
Darshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfDarshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdf
 

Ruby goes to Hollywood

  • 1. Ruby goes to Ruby, @elise_huard Rubykaigi 2011
  • 4.
  • 9. “No Global State” ” ” “Actors” ” ” “Partial Order of Execution” ” ”
  • 12. The universe customer X wake up customers? Barber sleeping/cutting customer X BarberShop customers waiting no
  • 13.
  • 14. Ruby
  • 15. “Rubinius Actors” @mentalguy
  • 18. class Barber include Celluloid::Actor attr_accessor :status def initialize(shop) @shop = shop end def cut_customer(name) puts " cutting customer #{name}" sleep(rand(5)) Text accident = rand(2) if accident puts " finished cutting #{name}" else puts " *** whoops, chopped #{name}'s head off ***" end shop.customer_leaves! end (...) end
  • 19. class Shop include Celluloid::Actor def initialize @barber = Barber.new(self) @chairs = [] puts "lights on ..." end def waiting_line @chairs.size end def new_customer(name) Text puts " customer arriving: #{name}" if waiting_line > 3 puts "*** sorry, #{name}, no room ***" else @chairs << name @barber.cut_customer!(name) end end def customer_leaves @chairs.shift end end
  • 20. shop = Shop.new ['jack', 'john', 'henry', 'tom', 'bob'].each do |customer| Text shop.new_customer!(customer) end shop.report
  • 24. %% shop %% barber_shop() -> io:format("lights on ... ~n"), ShopPid = self(), BarberPid = spawn(fun() -> barber(ShopPid) end), barber_shop_in_business(BarberPid, []). barber_shop_in_business(BarberPid, CustomersInChairs) -> receive {cut, Customer} -> % pop customer from list when hair is being cut remove_customer(BarberPid, CustomersInChairs, Customer); barbercheck -> respond_to_barber(BarberPid, CustomersInChairs); Customer -> io:format("~p arrives~n",[Customer]), % should check the number of customers waiting first % if all full: customer turned away add_customer_if_available(BarberPid, CustomersInChairs, Customer) end.
  • 25. %% barber %% barber(ShopPid) -> ShopPid ! barbercheck, receive wakeup -> barber(ShopPid); {customer, Customer} -> cut(ShopPid, Customer), barber(ShopPid) end. Text cut(ShopPid, Name) -> io:format("cutting ~p~n", [Name]), % take customer -> can be removed from waiting chairs ShopPid ! {cut, Name}, timer:sleep(random:uniform(10000)), io:format("finished cutting: ~p~n", [Name]).
  • 26. scenario() -> ShopPid = start_shop(), % send customers to the shop ShopPid ! 'john', ShopPid ! 'joe',Text timer:sleep(20000), ShopPid ! 'kevin', ShopPid ! 'richard', main_end.
  • 29. object Shop def initialize shop_pid = Process.current barber_pid = Process.spawn -> Barber.loop(shop_pid) @('barber_pid: barber_pid, 'shop_pid: shop_pid) end def loop(customers_in_chairs) IO.puts "shop loop #{customers_in_chairs}" receive match {'cut, customer} if customers_in_chairs.include?(customer) loop(customers_in_chairs.delete(customer)) else Text loop(customers_in_chairs) end match 'barbercheck IO.puts "barber checking ..." respond_to_barber(customers_in_chairs) match {'customer, customer} IO.puts("new customer #{customer}") add_customer(customers_in_chairs, customer) end end (...) end
  • 30. module Barber def loop(shop_pid) shop_pid <- 'barbercheck receive match 'wakeup IO.puts "wakeup" loop(shop_pid) match {'customer, customer} cut_hair(shop_pid, customer) loop(shop_pid) Text end end def cut_hair(shop_pid, customer) IO.puts "cutting customer #{customer}" shop_pid <- {'cut, customer} IO.puts "finished cutting customer #{customer}" end end
  • 31. pid = Process.spawn -> Shop.new.loop([]) IO.puts pid pid <- {'customer, "jack"} Text pid <- {'customer, "bob"}
  • 33.
  • 34. class BarberShop extends Actor { var barber: ActorRef = null var customersInChairs = List[Customer]() override def preStart() { barber = Actor.actorOf(new Barber(self)).start() } def receive = { case Customer(name) => if (customersInChairs.length >= 3) { Text println("sorry, no room for " + name) } else { customersInChairs = customersInChairs :+ Customer(name) barber ! WakeUp } case Cut(name) => customersInChairs = customersInChairs.tail case BarberCheck => // send first customer barber ! customersInChairs.head } }
  • 35. class Barber(val shop: ActorRef) extends Actor { def cut(name: String) = { shop ! Cut(name) } def receive = { case WakeUp => shop ! BarberCheck Text case Customer(name) => cut(name) shop ! BarberCheck } }
  • 36. package sleepingBarber import akka.actor.{Actor, ActorRef, ActorRegistry} import Actor._ import akka.actor.Actor.actorOf /* messages classes */ sealed trait BarberMessage case class Customer(name: String) extends BarberMessage case class Cut(name: String) extends BarberMessage case class BarberCheck() extends BarberMessage Text case class NoCustomers() extends BarberMessage case class WakeUp() extends BarberMessage object SleepingBarber { def main(args: Array[String]) : Unit = { val barberShop = Actor.actorOf[BarberShop].start() barberShop ! Customer("John") barberShop ! Customer("Jack") barberShop ! Customer("Arthur") Actor.registry.shutdownAll } }
  • 39.
  • 40. “easy to understand” “ ” “real encapsulation” ” ” “highly decentralized” ” ”
  • 41.
  • 42. “clear separation of parallel components” “ ” “livelocks - deadlocks still possible” “ - ”
  • 45. “Time to control shared state?” shared state
  • 47. ! Speaker Pictures Sherlock Jr (1924) @elise_huard Safety Last (1923) A Woman of Affairs (1928) Mysteries of a Barbershop (1923) Translation The Doll (1919) Intolerance (1926) Metropolis (1927) He Who Gets Slapped (1924) Conference Laughing Gravy (1931) Documentation Ruby Kaigi 2011 http://www.delicious.com/elisehuard/concurrency Sponsor Forward
  • 48. The End @ @@elise_huard Translation: