state doubts

Håkan Stenholm <>
Mon Nov 4 01:57:41 CET 2002

On söndag, nov 3, 2002, at 21:50 Europe/Stockholm, Enric Jaen wrote:

> Dear all,
> I am newbie in Erlang. I have two doubts I would like
> to clarify:
> *The state travels in every function call as a
> parameter.  Isn't this a cause of performance
> degradation when the state has a big size?

No, data is essentially passed as pointers, the state related cost is 
rather in modifying a piece of data as some copying may be needed to 
keep the old version around (when needed), e.g. :

V1 = {1,2,3},
V2 = setelement(2, V1, b), % same as, copy V1 into V2, set field 2 in 
V2 to b
f(V1), % V1 used later in function

Clever FP compiler usually minimize the need for copying.

> *AFAIK, Erlang is not multithreaded.

Yes and no, erlang processes serve much of the same purpose as threads, 
but you'll need to start several erlang nodes if you need to use more 
than one CPU.

> But, is there any
> example of a program implementing a barrier
> synchronization pattern?
> That is, a situation where
> several processes want to access to the same state at
> the same time and a server  must synchronize the
> access to this state?

Data in a erlang process is only visible to that process, you'll need 
to send a message (Pid ! Msg)  to request data from another process. 
There are also a number of data structures like ets and mnesia tables 
that can be accessed globally. Mnesia has transaction support, it is 
also common to use gen_servers to control access to services / data.

> Cheers,
>  -Enric
> _______________________________________________________________
> Yahoo! Messenger
> Nueva versión: Webcam, voz, y mucho más ¡Gratis!
> Descárgalo ya desde

More information about the erlang-questions mailing list