SlideShare uma empresa Scribd logo
1 de 133
Baixar para ler offline
Diana ORTEGA
@dicaormu
Paper and Book
Charles Antony Richard Hoare
“A paradigm for expressing
concurrency based on
message-passing”
Texte ici
Communicating Sequential Processes
Agenda
● Definitions : concurrency, parallelism, etc
● How do we usually deal with concurrency?
● Communicating Sequential Processes (CSP) and Actors
● Conclusion and takeaways
Go!
Communicating Sequential Processes
Definitions
Process
Communicating Sequential Processes
Definitions
Process
● Behaviour pattern of an object
● Implemented by functions
● Actions
Object
behaviour()
Communicating Sequential Processes
Definitions
Process
● Behaviour pattern of an object
● Implemented by functions
● Actions http://www.designmethodsandprocesses.co.uk/
public int function(int x){
System.out.println("hello");
…..
return 1;
}
Communicating Sequential Processes
Definitions
Process
● Behaviour pattern of an object
● Implemented by functions
● Actions
Texte ici
Concurrency vs Parallelism
Communicating Sequential Processes
Definitions
Parallelism in real life
Texte ici
Time
Process
Process
Process
Time
Process
Process
Process
Process
Concurrency enables parallelism
Definitions: Concurrency vs Parallelism
Communicating Sequential Processes
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
● How do I write in the same space of memory?
● What if a process crashes and it has a lock?
● Where do I locate this space?
Process 1 Process 2
Communicating Sequential Processes
Interaction sharing memory
Texte ici
Communicating Sequential Processes
Interaction sharing memory
Mutex Locks Semaphores
Threads
Texte ici
Interaction sharing memory
● Callback hell
● Fragmented logic
● How do we converge when we need to
handle state?
Texte ici
Communicating Sequential Processes
Interaction sharing memory
Deadlocks or race conditions
Foto: http://revistacorrientes.com/
Texte ici
● CSP
● Actor model
● Others (Amorphous computing, Flow-based programming)
Interaction by message passing
Communicating Sequential Processes
Texte ici
Reasoning
● Look around you, What do you see?
● A complex world interacting, with
independently behaving pieces
Communicating Sequential Processes
Definitions: Concurrent process
Texte ici
Communicating Sequential Processes
CSP (original)
Coroutines Subroutines
Texte ici
Communicating Sequential Processes
CSP (original)
Coroutines Subroutines
Processes
Texte ici
Communicating Sequential Processes
CSP (original)
Coroutine A
Coroutine B
Communication by
process name
Communication
by port
subroutine C
Texte ici
Communicating Sequential Processes
CSP (original)
Coroutine A
Coroutine B
Communication by
process name
Communication
by port
subroutine C
syntax?
Texte ici<input_command>::=<source>?<target_variable>
<output_command>::=<destination>!<expression>
<source>::=<process_name>
<destination>::=<process_name>
<process_name>::=<identifier>|<identifier>(<subscripts>)
<subscripts>::=<integer_expression>,{<integer_expression>}
<target_variable> :.---<simple_variable>l<structured_target>
<structured_target> :.---<constructor>(<target_variable_list>)
<target_variable_list> :~ <empty>[<target_variable>
{,<target_variable>}
Communicating Sequential Processes
Csp: communication
Texte ici<input_command>::=<source>?<target_variable>
<output_command>::=<destination>!<expression>
<source>::=<process_name>
<destination>::=<process_name>
<process_name>::=<identifier>|<identifier>(<subscripts>)
<subscripts>::=<integer_expression>,{<integer_expression>}
<target_variable> :.---<simple_variable>l<structured_target>
<structured_target> :.---<constructor>(<target_variable_list>)
<target_variable_list> :~ <empty>[<target_variable>
{,<target_variable>}
Communicating Sequential Processes
Csp: communication
Texte ici<input_command>::=<source>?<target_variable>
<output_command>::=<destination>!<expression>
<source>::=<process_name>
<destination>::=<process_name>
<process_name>::=<identifier>|<identifier>(<subscripts>)
<subscripts>::=<integer_expression>,{<integer_expression>}
<target_variable> :.---<simple_variable>l<structured_target>
<structured_target> :.---<constructor>(<target_variable_list>)
<target_variable_list> :~ <empty>[<target_variable>
{,<target_variable>}
Communicating Sequential Processes
Csp: communication
Texte ici<input_command>::=<source>?<target_variable>
<output_command>::=<destination>!<expression>
<source>::=<process_name>
<destination>::=<process_name>
<process_name>::=<identifier>|<identifier>(<subscripts>)
<subscripts>::=<integer_expression>,{<integer_expression>}
<target_variable> :.---<simple_variable>l<structured_target>
<structured_target> :.---<constructor>(<target_variable_list>)
<target_variable_list> :~ <empty>[<target_variable>
{,<target_variable>}
Communicating Sequential Processes
Csp: communication
Texte ici
αc(P)={v |c.v ∈αP}
Communicating Sequential Processes
What does CSP say?
Texte ici
αc(P)={v |c.v ∈αP}
Communicating Sequential Processes
What does CSP say?
ProcessProcess
Texte ici
αc(P)={v |c.v ∈αP}
Communicating Sequential Processes
What does CSP say?
Value of
message
Texte ici
αc(P)={v |c.v ∈αP}
Communicating Sequential Processes
What does CSP say?
communication
event
Texte ici
αc(P)={v |c.v ∈αP}
Communicating Sequential Processes
What does CSP say?
Channels have type
Texte ici
Process1 Process2
Communicating Sequential Processes
CSP
Texte ici
Process1 Process2
Communicating Sequential Processes
CSP
Channel
Texte ici
Process1 Process2
Communicating Sequential Processes
CSP
Channel
Texte ici
“The Actor model adopts the philosophy
that everything is an actor. ”
Wikipedia
Communicating Sequential Processes
Actor model
Texte ici
Actor1 Actor2
Communicating Sequential Processes
Actor model
Texte ici
Actor1 Actor2
MailBox MailBox
Communicating Sequential Processes
Actor model
Texte ici
Actor1 Actor2
MailBox MailBox
Communicating Sequential Processes
Actor model
Texte iciActor System
Address
Address
Address
Communicating Sequential Processes
● processing
● storage
● communication
Actors
Texte ici
Communicating Sequential Processes
CSP and Actors
Program
Texte ici
Communicating Sequential Processes
CSP and Actors
Process Process Process Process
Texte ici
Communicating Sequential Processes
CSP and Actors
Process1 Process2 Process3 Process4
I speak CSP!! me too!! :D
I’m an
Actor
me
too!
Texte ici
Sending first
Texte ici
Time Time
CSP Actors
Communicating Sequential Processes
CSP and Actors
Texte ici
Time Time
Process1 writing
Actor writing
Communicating Sequential Processes
CSP and Actors
Texte ici
Time Time
Process1 writing
Actors
Communicating Sequential Processes
CSP and Actors
Process1 waiting
Texte ici
Time Time
Process2 reading
Actors
Communicating Sequential Processes
CSP and Actors
Process1 writing
Process1 waiting
Texte ici
Time Time
Actors
Communicating Sequential Processes
CSP and Actors
Process2 reading
Texte ici
Reading first
Texte ici
Time Time
Process1 waiting
Communicating Sequential Processes
CSP and Actors
Actor1 waiting
Texte ici
Time Time
Process1 waiting
Communicating Sequential Processes
CSP and Actors
Actor1 waiting
Process2 Writing Actor2 Writing
Texte ici
Time Time
Process1 waiting
Communicating Sequential Processes
CSP and Actors
Actor1 waiting
Process2 Writing Actor2 Writing
Process1 reading Actor1 reading
Texte ici
Time Time
Process1 waiting
Communicating Sequential Processes
CSP and Actors
Actor1 waiting
Process2 Writing Actor2 Writing
Process1 reading Actor1 reading
Process1 Processing Actor1 processing
Texte ici
Time Time
Process1 waiting
Communicating Sequential Processes
CSP and Actors
Actor1 waiting
Process2 Writing Actor2 Writing
Process1 reading Actor1 reading
Process1 Processing Actor1 waiting
Texte ici
The sieve of Eratosthenes.
2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
Communicating Sequential Processes
Example
Texte ici
The sieve of Eratosthenes.
2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
p =2
look for multiples
starting by p^2
Communicating Sequential Processes
Example
Texte ici
The sieve of Eratosthenes.
3 5 7 9
11 13 15 17 19
21 23 25 27 29
31 33 35 37 39
41 43 45 47 49
51 53 55 57 59
61 63 65 67 69
71 73 75 77 79
81 83 85 87 89
91 93 95 97 99
p =3
look for multiples
starting by p^2
Communicating Sequential Processes
Example
Texte ici
The sieve of Eratosthenes.
5 7 11 13
17 19 23 25 29
31 35 37 41 43
47 49 53 55 59
61 65 67 71 73
77 79 83 85 89
91 95 97
p =5
look for multiples
starting by p^2
Communicating Sequential Processes
Example
Texte ici
The sieve of Eratosthenes.
7 11 13 17
19 23 29 31 37
41 43 47 49 53
59 61 67 71 73
77 79 83 89 91
97
p =7
look for multiples
starting by p^2
Communicating Sequential Processes
Example
Texte ici
The sieve of Eratosthenes.
11 13 17 19
23 29 31 37 41
43 47 53 59 61
67 71 73 79 83
89 97
p =11
look for multiples
starting by p^2
Communicating Sequential Processes
Example
Texte ici
Communicating Sequential Processes
Solution CSP
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch, 100) // Launch Generate goroutine.
Sieve(ch)
}
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
func Generate(ch chan<- int, number int) {
for i := 2; i < number; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
Texte ici
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch, 100) // Launch Generate goroutine.
Sieve(ch)
}
ch: channel int
Communicating Sequential Processes
Explanation A channel in Go provides a
connection between two
goroutines, allowing them to
communicate.
Texte ici
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch, 100) // Launch Generate goroutine.
Sieve(ch)
}
stack Generate
Communicating Sequential Processes
Explanation
ch: channel int
It's an independently
executing function,
launched by a go
statement.
Texte ici
func Generate(ch chan<- int, number int) {
for i := 2; i < number; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
Communicating Sequential Processes
Explanation
stack Generate
number := 100
i:=2
ch: channel int
i
2
Synchronisation, it waits for a receiver to be
ready.
Texte ici
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch, 100) // Launch Generate goroutine.
Sieve(ch)
}
Communicating Sequential Processes
Explanation
stack Generate
ch: channel int
2
Texte ici
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
prime :=2
Communicating Sequential Processes
Explanation
stack Generate
ch: channel int
2
synchronization, it will wait
for a value to be sent
Texte ici
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
Communicating Sequential Processes
Explanation
stack Generate
ch: channel int
ch1: channel int
Texte ici
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
} stack Filter
Communicating Sequential Processes
Explanation
stack Generate
ch: channel int
ch1: channel int
Channels both
communicate and
synchronize
Texte ici
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
Communicating Sequential Processes
Explanation
stack Filterstack Generate
ch: channel int
ch1: channel int
Texte ici
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
prime :=...
Communicating Sequential Processes
Explanation
stack Filterstack Generate
ch: channel int
ch1 (new ch): channel int
Texte ici
func Generate(ch chan<- int, number int) {
for i := 2; i < number; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
Communicating Sequential Processes
Explanation
prime :=...
stack Filterstack Generate
number := 100
i:=3
ch: channel int
ch1 (new ch): channel int
i
3
Texte ici
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
Communicating Sequential Processes
prime :=...
stack Filter
prime:=2
stack Generate
ch(now in): channel int
ch1 (now out): channel int
i:=33
Explanation
A sender and receiver must
both be ready to play their
part in the communication.
Otherwise we wait until they
are
Texte ici
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
Communicating Sequential Processes
Explanation
prime :=...
stack Filter
prime:=2
stack Generate
ch(now in): channel int
ch1 (now out): channel int
i:=3
3
Texte ici
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
prime := 3
Communicating Sequential Processes
Explanation
stack Filterstack Generate
ch: channel int
ch1 (new ch): channel int
3
Texte ici
func Generate(ch chan<- int, number int) {
for i := 2; i < number; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
Communicating Sequential Processes
Explanation
stack Filterstack Generate
number := 100
i:=4
ch: channel int
ch1: channel int
i
4
Texte ici
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
Communicating Sequential Processes
Explanation
stack Filter
prime:=2
stack Generate
ch(now in): channel int
ch1(now out): channel int
i:=4
4
Texte ici
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
Communicating Sequential Processes
Explanation
stack Filter
prime:=2
stack Generate
ch(now in): channel int
ch1(now out): channel int
i:=4
Texte ici
And so on…..
Communicating Sequential Processes
Explanation
Texte ici
Result
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
Texte ici
Communicating Sequential Processes
Solution Actor system
Texte ici
implicit val system = ActorSystem("EratosthenesSystem")
implicit val ec = system.dispatcher
Communicating Sequential Processes
Explanation
Texte ici
val upper = 100
val eventualPrimes = PrimeFinderCalculator(upper)
eventualPrimes.onComplete {
case Success(primes) =>
println(primes)
system.terminate()
case Failure(error) =>
Console.err.println(error)
system.terminate()
}
Communicating Sequential Processes
Explanation
Texte ici
object PrimeFinderCalculator {
def apply(upper: Int, nrOfWorkers: Int = 2)
(implicit system: ActorSystem, timeout: Timeout): Future[List[Int]] = {
val master = system.actorOf(Master.props(upper), name = Master.name)
system.actorOf(Eratosthenes.props(), name = Eratosthenes.name)
(master ? Master.Messages.FindPrimes).mapTo[List[Int]]
}
}
}
Communicating Sequential Processes
Explanation
Texte iciActor System
/root
/user
/Eratosthenes:era
tosthenes
/Master:
master
Communicating Sequential Processes
Explanation
Texte ici
object PrimeFinderCalculator {
def apply(upper: Int, nrOfWorkers: Int = 2)
(implicit system: ActorSystem, timeout: Timeout): Future[List[Int]] = {
val master = system.actorOf(Master.props(upper), name = Master.name)
system.actorOf(Eratosthenes.props(), name = Eratosthenes.name)
(master ? Master.Messages.FindPrimes).mapTo[List[Int]]
}
}
}
Communicating Sequential Processes
Explanation
Texte iciActor System
/root
/user
/Eratosthenes:era
tosthenes
/Master:
master
Communicating Sequential Processes
findPrimes
Explanation
Texte ici
class Master(upper: Int) extends Actor {
var client: Option[ActorRef] = None
def receive: Receive = {
case FindPrimes =>
client = Some(sender)
val sieveRef = context.actorSelection(s"/user/${Eratosthenes.name}")
sieveRef ! Eratosthenes.Messages.Sieve(self, Nil, (2 to upper).toList)
case Result(list) =>
client.foreach(_ ! list)
}
}
Messages are not
anonymous
Communicating Sequential Processes
Explanation
Texte ici
class Master(upper: Int) extends Actor {
var client: Option[ActorRef] = None
def receive: Receive = {
case FindPrimes =>
client = Some(sender)
val sieveRef = context.actorSelection(s"/user/${Eratosthenes.name}")
sieveRef ! Eratosthenes.Messages.Sieve(self, Nil, (2 to upper).toList)
case Result(list) =>
client.foreach(_ ! list)
}
}
I know all actors in the system.
I can look for an actor in a path and send
messages
Communicating Sequential Processes
Explanation
Texte iciActor System
/root
/user
/Eratosthenes:era
tosthenes
/Master:
master
Communicating Sequential Processes
Sieve(self,nil, [2,3,..])
Explanation
Texte ici
class Eratosthenes extends Actor with ActorLogging {
def receive: Receive = {
case Sieve(parent, primes, remaining) =>
remaining match {
case Nil =>
parent ! Master.Messages.Result(primes)
case h :: tail =>
self ! Sieve(parent, primes ++ List(h), tail.filter { x => x % h != 0 })
}
}
}
Send message to itself with
remaining list
Explanation
Texte iciActor System
/root
/user
/Eratosthenes:era
tosthenes
/Master:
master
Communicating Sequential Processes
Sieve(parent,[2], [3,5..])
Explanation
Texte ici
class Eratosthenes extends Actor with ActorLogging {
def receive: Receive = {
case Sieve(parent, primes, remaining) =>
remaining match {
case Nil =>
parent ! Master.Messages.Result(primes)
case h :: tail =>
self ! Sieve(parent, primes ++ List(h), tail.filter { x => x % h != 0 })
}
}
}
send primes list to parent
Explanation
Texte iciActor System
/root
/user
/Eratosthenes:era
tosthenes
/Master:
master
Communicating Sequential Processes
Result([2,3,5,7,...])
Explanation
Texte ici
class Master(upper: Int) extends Actor {
var client: Option[ActorRef] = None
def receive: Receive = {
case FindPrimes =>
client = Some(sender)
val sieveRef = context.actorSelection(s"/user/${Eratosthenes.name}")
sieveRef ! Eratosthenes.Messages.Sieve(self, Nil, (2 to upper).toList)
case Result(list) =>
client.foreach(_ ! list)
}
}
send response
Communicating Sequential Processes
Explanation
Texte ici
Communicating Sequential Processes
Result
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
Texte ici
Building a small actor system using channels
Mixing metaphors
Process1 Actor1
Channel
Texte ici
Building a small actor system using channels
Mixing metaphors
Actor1Process1Channel
Actors are directly adressable. Channels are anonymous
Texte ici
Building a small actor system using channels
Mixing metaphors
Mailboxes are only addressable by owning actor
Actor1 Actor2
Mailbox actor1 Mailbox actor2
Texte ici
Building a small actor system using channels
Mixing metaphors
Channels have type
Process1Channel (Int)
Texte ici
Building a small actor system using channels
Mixing metaphors
In actor model, only receiver blocks
Process2ChannelProcess1
Texte ici
● communicating haskell processes
● go
● Clojure
● Javascript(js-csp)
Communicating Sequential Processes
Who does csp?
Texte ici
● erlang
● elixir
● Akka
Communicating Sequential Processes
Who does actors?
Texte ici
Takeaways
Communicating Sequential Processes
Concurrent programming involves at least three distinct concerns: concurrency,
mutual exclusion, and synchronisation
Texte ici
Takeaways
Communicating Sequential Processes
Use the right tool for the job
Texte ici
Takeaways
Communicating Sequential Processes
Actors and channels are often confused, we saw a mailbox implementation through
channels to characterize them and “live” the differences
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch, 100) // Launch Generate goroutine.
Sieve(ch)
}
func Sieve(ch chan int) {
prime := <-ch
print(prime, "n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
Sieve(ch1)
}
A channel in Go provides a
connection between two
goroutines, allowing them to
communicate.
It's an independently
executing function,
launched by a go
statement.
synchronization, it will wait
for a value to be sent
Channels both
communicate and
synchronize
channel int
stack Generate
func Generate(ch chan<- int, number int) {
for i := 2; i < number; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
func Filter(in <-chan int, out chan<- int, prime int) {
for {
i := <-in // Receive value from 'in'.
if i%prime != 0 {
out <- i // Send 'i' to 'out'.
}
}
}
Synchronisation, it waits for a receiver to be
ready.
A sender and receiver must
both be ready to play their
part in the communication.
Otherwise we wait until they
are
Texte ici
Building a small actor system using channels
Mixing metaphors
Message ordering
Texte ici
Building a small actor system using channels
Mixing metaphors
type Actor struct {
…...
mailbox chan interface{}
}
func (actor *Actor) doSomething(message interface{}) {
select {
case actor.mailbox <- message:
default:
//throw message away
}
}
func (actor *Actor) receive(){
for{
message := <- actor.mailbox
//deal with action
…...
}
}
Texte ici
How many messages should we wait?
Mixing metaphors
1 message, the sender could block
∞ is not possible
n=?
Texte ici
Communicating Sequential Processes
Building a channel using Actors
defmodule Chan.Chan do
...
def loop do
receive do
{msg,caller} ->
cond do
is_integer(msg) -> Kernel.send(caller, msg)
true -> loop()
end
end
end
…
end
test "echo" do
{:ok, pid} = Chan.start_link()
Chan.send(pid, 1)
assert_receive 1
Chan.send(pid, :hi)
refute_receive :hi
end
Texte ici
Building a channel using Actors
Building a channel using Actors
defmodule Chan.Chan do
...
def loop do
receive do
{msg,caller} ->
cond do
is_integer(msg) -> Kernel.send(caller, msg)
true -> loop()
end
end
end
…
end

Mais conteúdo relacionado

Semelhante a XebiCon'17 : Communicating sequential processes - Diana Ortega

Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...
Edmond Lepedus
 
Intelligent Handwriting Recognition_MIL_presentation_v3_final
Intelligent Handwriting Recognition_MIL_presentation_v3_finalIntelligent Handwriting Recognition_MIL_presentation_v3_final
Intelligent Handwriting Recognition_MIL_presentation_v3_final
Suhas Pillai
 

Semelhante a XebiCon'17 : Communicating sequential processes - Diana Ortega (20)

HCI 3e - Ch 16: Dialogue notations and design
HCI 3e - Ch 16:  Dialogue notations and designHCI 3e - Ch 16:  Dialogue notations and design
HCI 3e - Ch 16: Dialogue notations and design
 
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
 
WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactiv...
WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactiv...WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactiv...
WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactiv...
 
PPT_203105211_3.pptx
PPT_203105211_3.pptxPPT_203105211_3.pptx
PPT_203105211_3.pptx
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
 
Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...Understanding Natural Languange with Corpora-based Generation of Dependency G...
Understanding Natural Languange with Corpora-based Generation of Dependency G...
 
An Actor Model in Go
An Actor Model in GoAn Actor Model in Go
An Actor Model in Go
 
Processing Techniques
Processing TechniquesProcessing Techniques
Processing Techniques
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
 
An Actor Model in Go
An Actor Model in GoAn Actor Model in Go
An Actor Model in Go
 
Using Pony for Fintech
Using Pony for FintechUsing Pony for Fintech
Using Pony for Fintech
 
Understanding F# Workflows
Understanding F# WorkflowsUnderstanding F# Workflows
Understanding F# Workflows
 
Algorithm in Computer, Sorting and Notations
Algorithm in Computer, Sorting  and NotationsAlgorithm in Computer, Sorting  and Notations
Algorithm in Computer, Sorting and Notations
 
Distributed systems vs compositionality
Distributed systems vs compositionalityDistributed systems vs compositionality
Distributed systems vs compositionality
 
Intelligent Handwriting Recognition_MIL_presentation_v3_final
Intelligent Handwriting Recognition_MIL_presentation_v3_finalIntelligent Handwriting Recognition_MIL_presentation_v3_final
Intelligent Handwriting Recognition_MIL_presentation_v3_final
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 Recap
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
 
NLTK
NLTKNLTK
NLTK
 
Elixir and OTP
Elixir and OTPElixir and OTP
Elixir and OTP
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 

Mais de Publicis Sapient Engineering

Mais de Publicis Sapient Engineering (20)

XebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humain
XebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humainXebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humain
XebiCon'18 - L'algorithme de reconnaissance de formes par le cerveau humain
 
Xebicon'18 - IoT: From Edge to Cloud
Xebicon'18 - IoT: From Edge to CloudXebicon'18 - IoT: From Edge to Cloud
Xebicon'18 - IoT: From Edge to Cloud
 
Xebicon'18 - Spark in jail : conteneurisez vos traitements data sans serveur
Xebicon'18 - Spark in jail : conteneurisez vos traitements data sans serveurXebicon'18 - Spark in jail : conteneurisez vos traitements data sans serveur
Xebicon'18 - Spark in jail : conteneurisez vos traitements data sans serveur
 
XebiCon'18 - Modern Infrastructure
XebiCon'18 - Modern InfrastructureXebiCon'18 - Modern Infrastructure
XebiCon'18 - Modern Infrastructure
 
XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...
XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...
XebiCon'18 - La Web App d'aujourd'hui et de demain : état de l'art et bleedin...
 
XebiCon'18 - Des notebook pour le monitoring avec Zeppelin
XebiCon'18 - Des notebook pour le monitoring avec Zeppelin XebiCon'18 - Des notebook pour le monitoring avec Zeppelin
XebiCon'18 - Des notebook pour le monitoring avec Zeppelin
 
XebiCon'18 - Event Sourcing et RGPD, incompatibles ?
XebiCon'18 - Event Sourcing et RGPD, incompatibles ?XebiCon'18 - Event Sourcing et RGPD, incompatibles ?
XebiCon'18 - Event Sourcing et RGPD, incompatibles ?
 
XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?
XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?
XebiCon'18 - Deno, le nouveau NodeJS qui inverse la tendance ?
 
XebiCon'18 - Boostez vos modèles avec du Deep Learning distribué
XebiCon'18 - Boostez vos modèles avec du Deep Learning distribuéXebiCon'18 - Boostez vos modèles avec du Deep Learning distribué
XebiCon'18 - Boostez vos modèles avec du Deep Learning distribué
 
XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...
XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...
XebiCon'18 - Comment j'ai développé un jeu vidéo avec des outils de développe...
 
XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !
XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !
XebiCon'18 - Les utilisateurs finaux, les oubliés de nos produits !
 
XebiCon'18 - Comment fausser l'interprétation de vos résultats avec des dataviz
XebiCon'18 - Comment fausser l'interprétation de vos résultats avec des datavizXebiCon'18 - Comment fausser l'interprétation de vos résultats avec des dataviz
XebiCon'18 - Comment fausser l'interprétation de vos résultats avec des dataviz
 
XebiCon'18 - Le développeur dans la Pop Culture
XebiCon'18 - Le développeur dans la Pop Culture XebiCon'18 - Le développeur dans la Pop Culture
XebiCon'18 - Le développeur dans la Pop Culture
 
XebiCon'18 - Architecturer son application mobile pour la durabilité
XebiCon'18 - Architecturer son application mobile pour la durabilitéXebiCon'18 - Architecturer son application mobile pour la durabilité
XebiCon'18 - Architecturer son application mobile pour la durabilité
 
XebiCon'18 - Sécuriser son API avec OpenID Connect
XebiCon'18 - Sécuriser son API avec OpenID ConnectXebiCon'18 - Sécuriser son API avec OpenID Connect
XebiCon'18 - Sécuriser son API avec OpenID Connect
 
XebiCon'18 - Structuration du Temps et Dynamique de Groupes, Théorie organisa...
XebiCon'18 - Structuration du Temps et Dynamique de Groupes, Théorie organisa...XebiCon'18 - Structuration du Temps et Dynamique de Groupes, Théorie organisa...
XebiCon'18 - Structuration du Temps et Dynamique de Groupes, Théorie organisa...
 
XebiCon'18 - Spark NLP, un an après
XebiCon'18 - Spark NLP, un an aprèsXebiCon'18 - Spark NLP, un an après
XebiCon'18 - Spark NLP, un an après
 
XebiCon'18 - La sécurité, douce illusion même en 2018
XebiCon'18 - La sécurité, douce illusion même en 2018XebiCon'18 - La sécurité, douce illusion même en 2018
XebiCon'18 - La sécurité, douce illusion même en 2018
 
XebiCon'18 - Utiliser Hyperledger Fabric pour la création d'une blockchain pr...
XebiCon'18 - Utiliser Hyperledger Fabric pour la création d'une blockchain pr...XebiCon'18 - Utiliser Hyperledger Fabric pour la création d'une blockchain pr...
XebiCon'18 - Utiliser Hyperledger Fabric pour la création d'une blockchain pr...
 
XebiCon'18 - Ce que l'histoire du métro Parisien m'a enseigné sur la création...
XebiCon'18 - Ce que l'histoire du métro Parisien m'a enseigné sur la création...XebiCon'18 - Ce que l'histoire du métro Parisien m'a enseigné sur la création...
XebiCon'18 - Ce que l'histoire du métro Parisien m'a enseigné sur la création...
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

XebiCon'17 : Communicating sequential processes - Diana Ortega