1. 程式人生 > >8.2 編寫健壯的應用程式-健壯的服務程序

8.2 編寫健壯的應用程式-健壯的服務程序

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);
            false ->
                From ! {resource_alloc, error},
                server(Free, Allocated)
        end.