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

Roger Larsson <>
Mon Nov 5 19:53:08 CET 2007


But do they need to have a registered name?
I would really avoid registering a constructed name like "customer_23",
remember that this name has to be kept track of somewhere.
And how do you know that it is #23 actually? My guess is that you have made a
query in the first place, try to let it return the PID directly instead of 
23...

/RogerL

On måndag 05 november 2007, Alexander Lamb wrote:
> 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.ht
> >ml
> > http://www.erlang.org/pipermail/erlang-questions/2007-September/029379.ht
> >ml
> >
> > 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
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list