🎬 Animated view
Colored tokens show what is happening: purple = system process unblocked, green = user process unblocked, blue = immediate allocation or printers returned.
Procedure Request(K, type)
if (Available < K)
then
switch(type):
case system: enqueue(SysQueue, K-Available); Available=0;
syst.wait;
case user: enqueue(UsrQueue, K);
user.wait;
else Available = Available - K;
end if;
Procedure Release(m)
Step 0Available = Available + m;
while(syst.empty==
false and Available >= Head(SysQueue))
do
Step 1Available -= Head(SysQueue); Dequeue(SysQueue);
syst.signal;
end while
if(syst.empty==
false)
then
Step 2Head(SysQueue) = Head(SysQueue) - Available; Available = 0;
end if;
while(User.empty==
false and Available >= Head(UsrQueue))
do
Step 3Available -= Head(UsrQueue); Dequeue(UsrQueue);
user.signal;
end while
Safety guard: Release(m) is refused if m exceeds the number of printers actually in use, which guarantees the invariant 0 ≤ Available ≤ N.