Erlang PID List

In short, I am trying to reproduce the problem of a sleeping hairdresser in Erlang.

In my decision, I decided that for all pending processes I would put them on a list. Then, as soon as this happens, I will go from this PID list.

Sorry when I call

length(myListOfPids).

it does not work, for example:

length([<0.46.0>]).
* 2: syntax error before: '<'

Is there a way to store the PID code so that I can remember and use them normally? i.e.

PID ! message

... just in case, the actual error that I get when starting my program matters:

=ERROR REPORT==== 1-Jul-2010::05:50:40 ===
Error in process <0.44.0> with exit value:
{badarg,[{erlang,length,[<0.46.0>]},{barber1,waitingRoom,2}]}

barber1 is my module, waitingRoom is a function that keeps track of which processes are waiting

+5
source share
5 answers

Pids, , . ?

:

-module(test).
-export([loop/0]).

loop() ->
    receive
        {hello} ->
            io:format("Hello world!~n"),
            loop()
end.

:

 Eshell V5.7.5  (abort with ^G)
 1> Pid = spawn(fun test:loop/0).
 <0.35.0>
 2> L = [Pid].
 [<0.35.0>]
 3> length(L). 
 1
+6

Pid , pid/3.

1 > length ([pid (0,35,0)]).

, Pid , pid node, , .

, , .

{badarg, [{, , [< 0.46.0 > ]}, {barber1, waitingRoom, 2}]}

erlang: length/1 badarg. {erlang, length, [< 0.46.0 > ]} - , erlang: length. , :

1 > erlang: length (pid (0,46,0)).

:

1 > erlang: length ([pid (0,46,0)]).

(, erlang erlang. :

** : length/1, (< 0.35.0 > )

, , erlang.)

+10

:

=ERROR REPORT==== 1-Jul-2010::05:50:40 ===
Error in process <0.44.0> with exit value:
{badarg,[{erlang,length,[<0.46.0>]},{barber1,waitingRoom,2}]}

, length(<0.46.0>), length([<0.46.0>]) ( , PID , ). . length , : PID, , .

+5

, <0.46.0> - , PID, . list_to_pid("<0.46.0>"). , PID ( , spawn ..), Erlang.

+3

pid - : spawn/1, spawn/3, spawn_link/1, spawn_link/3 proc_lib.

pid c: pid/3, c:pid(0,25,0), <0.25.0>. . list_to_pid/1, .

pids, . Pid , . pid , , , . , . , , .

The cleanest way to do this is to use the return value of the spawn function. Manual pid creation should be left only as a debugging solution.

+2
source

All Articles