<< Prev | - Up - | Next >> |
Every agents is realized as its own thread which is created when the agent is started, and killed when the exception done
is raised. Killing a thread is necessary only in order to clean the space in the store occupied by the thread.
local
<Process>
in
proc{StartAgent Agent}
{Board.post newAgent}
thread
try {ForAll Board.items
proc {$ Item}
{Process Agent Item Board}
end}
catch done then skip end
end
{Show done}
end
end
Every agent processes every item on the board by calling the procedure Process
. When the control item stop
is found, the exception done is raised and the thread of the agent is killed. All other control items are ignored. An information item is processed by calling the procedure ProcessInfo
which is an extern parameter of the concurrent agenda model.
proc{Process Agent Item Board}
case Item
of stop then raise done end
elseof info(Info) then
NewObjects = {ProcessInfo Agent Info}
in
{ForAll NewObjects
proc{$ O}
case O of agent(A) then {StartAgent A}
elseof info(I) then {Board.post info(I)}
end
end}
{Board.post infoProcessed}
else skip % other control items
end
end
<< Prev | - Up - | Next >> |