server(Free, Allocated) -> receive {From, alloc} -> allocate(Free, Allocated, From); {From, {free, R}} -> free(Free, Allocated, From, R); {'EXIT', From, _} -> check(Free, Alloctaed, From); end. allocate([R|Free], Allocated, From) -> link(From), %%% Causes 'EXIT' messages to be sent %%% From ! {resource_alloc, {yes, R}}, server(Free, [{R,From}|Allocated]); allocate([], Allocated, From) -> From ! {resource_alloc, no}, server([], Allocated). free(Free, Allocated, From, R) -> case lists:member({R, From}, Allocated) of true -> From ! {resource_alloc, yes}, Allocated1 = lists:delete({R, From}, Allocated), case lists:keysearch(From, 2, Allocated1) of false -> unlink(From); _ -> true end, server([R|Free], Allocated1); ...