Slide 24
Slide 24 text
%% shop %%
barber_shop() ->
io:format("lights on ... ~n"),
ShopPid = self(),
BarberPid = spawn(fun() -> barber(ShopPid) end),
barber_shop_in_business(BarberPid, []).
barber_shop_in_business(BarberPid, CustomersInChairs) ->
receive
{cut, Customer} ->
% pop customer from list when hair is being cut
remove_customer(BarberPid, CustomersInChairs,
Customer);
barbercheck ->
respond_to_barber(BarberPid, CustomersInChairs);
Customer ->
io:format("~p arrives~n",[Customer]),
% should check the number of customers waiting first
% if all full: customer turned away
add_customer_if_available(BarberPid, CustomersInChairs,
Customer)
end.