Posts Tagged ‘sequential programming

30
Jul
09

using concurrency primitives

Everything we’ve learned about sequential programming is still true
for concurrent programming. All we have to do is to add the following
primitives:

Pid = spawn(Fun)
Pid ! Message
receiveend

Pid = spawn(Fun)

Creates a new concurrent process that evaluates Fun. The new
process runs in parallel with the caller. spawn returns a Pid (short
for process identifier). You can use Pid to send messages to the
process.

Pid ! Message

Sends Message to the process with identifier Pid. Message sending
is asynchronous. The sender does not wait but continues with
what it was doing. ! is called the send operator.
Pid ! M is defined to be M—the message sending primitive ! returns
the message itself. Because of this, Pid1 ! Pid2 ! … ! M means send
the message M to all the processes Pid1, Pid2, and so on.

receiveend

Receives a message that has been sent to a process. It has the following skeleton :

receive
_ ->
ok
end.

To be continue with simple example …




 

May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  

del.icio.us

Con gái yêu.

CIMG0003

16/01/2010

Đầu tóc rối tung ...

More Photos

jabber

cuonglb@jabber.mobi
cuonglb@jabber.org
cuonglb@gmail.com
cuonglb@facemain.com
cuong@livemarkets.com
cuonglb@moo.im
cuonglb@jabber.snc.ru
cuonglb@alpha-labs.net
cuonglb@jaim.at
cuonglb@jabber.bluendo.com

Twitter Updates


Follow

Get every new post delivered to your Inbox.