[erlang-questions] Imagine every (active) entity is a process

Alexander Lamb alexander.lamb@REDACTED
Mon Nov 5 16:44:37 CET 2007


And what about just letting the race condition occur:

The first one which manages to create a  process for a given name  
succeeds. Obviously, the second one will not succeed with the same  
name if the process is already registered under that name.
No problem, just catch the error and loop back to querying the  
registered processes for that name (which at that time will exist).

Alex

Le 5 nov. 07 à 16:32, Taavi Talvik a écrit :

>> When I would want to start working on customer "23" for example, I
>> will first need to check if customer "23" is already an active
>> process. If yes, I get the Pid and exchange whatever messages I need
>> with customer "23". If not, I create the process and proceed.
>> Now, obviously, for my process to be known by all potential users of
>> the process, I must register the process using the register(Name,Pid)
>> function. As a name I could concatenate the entity name and its
>> primary key (in my case: "customer_23").
>>
>> Isn't there a race condition here. Since I have to check first if a
>> process exists before creating it, I might end up in a situation  
>> where
>> two other processes are doing the same thing and creating twice a
>> process for the same entity. The second would obviously fail and we
>> could catch the error. But is this a correct way of proceeding? Also,
>> is it possible to have thousands of registered processes (as opposed
>> to non registered processes)?
>
> You can serialize process lookup and creation
> 	- yet another process, which is responsible for looking up "actual  
> serving process"
> 	and if necessary creating new process
> 	- if you keep names private only way to access workers is through
> 	name_resolver and no race any more.
> 	- of course this creates new bottleneck
>
> look at global http://erlang.org/doc/man/global.html
>
> Just register() is only one building block. You need name lookup,  
> new process creation
> and registration coordinated.
>
> references:
> http://www.erlang.org/pipermail/erlang-questions/2007-September/029373.html
> http://www.erlang.org/pipermail/erlang-questions/2007-September/029379.html
>
> best regards,
> taavi
>
>

--
Alexander Lamb
Founding Associate
RODANOTECH Sàrl

4 ch. de la Tour de Champel
1206 Geneva
Switzerland

Tel:  022 347 77 37
Fax: 022 347 77 38

http://www.rodanotech.ch






More information about the erlang-questions mailing list