Sunday, May 8, 2011

Can A Woman Get A Hernia




We've discussed this before:
http://emanuelpeg.blogspot.com/2010/09/concurrencia-en-erlang.html
But let's do a review, Erlang is a concurrent programming language and a delivery system that includes a virtual machine and libraries. It was designed in the company Ericsson for distributed applications, fault tolerant, soft-real-time and uninterrupted operation. Provides hot swapping of code so that it can be changed without stopping the system. Originally, it was a proprietary language Erlang from Ericsson, but was licensed as open source software in 1998. The implementation of Ericsson is primarily performed but also includes a HIPE compiler (only supported on some platforms).
Among the major achievements of the platform we note that facebook chat and CouchDB document database.
No doubt one thing that makes it special is how Erlang handles concurrency. Erlang does not handle the competition with thread as we have used C, C + + or Java. Erlang solves programming model CONCURRENT by actors. The actor model of concurrency is a computational model that treats "actors" as the universal primitives of parallel digital computation: in response to a message received, an actor can make local decisions, create more actors, it sends more messages and determine how to respond to the next message received. -module (hello).
-export ([loop / 0]).
loop () -> Receive

%
greets a well-known "known" ->
io: format ("Hello!"),
loop ();
% A stranger, do not greet
_ - >
io: format ("..."),
loop ()
end.

In the first line declare the module and then import the loop function, with which we define an empty function and iterate forever. Receive to receive a message similar to the swich, wait for a message and the callback executes the code structure which corresponds to the message sent and the "_" as the default is in c, c + + or Java. First compile

:

1> c (hello).
{ok}

greeter spawn can be generated with a process, spawn will return the PID of the process, which we will use to send messages.

2> Pid = spawn (fun greeter: loop / 0).
\u0026lt;0.38.0>

Now we are going to send a message:

4> Pid! "Known."
Hello! "Known"

5> Pid! "Pepe".
... "Pepe"

As expected just say hello to acquaintances. Operator ! send messages to an actor from its Pid.

This is a small example of erlang concurrency management. The way it handles the Scala audience was inspired by Erlang.


0 comments:

Post a Comment