TYPE semaphore = RECORD
head, tail : POINTER TO pcb
count : integer ;
END
PROCEDURE P(s:semaphore) ; {wait}
IF s.count > 0
THEN s.count := s.count - 1 ;
ELSE current^.state := blocked ;
addtail(current,s) {insert at end of Queue}
END
END
PROCEDURE V(s:semaphore)
IF s.head = null {nothing waiting}
THEN s.count := s.count + 1 ;
ELSE s.head^.state := runnable ;
remove pcb at head of Q ;
schedule it {insert in ready Q} ;
END
END
PROCEDURE Initsemaphore(s,n:integer) ;
{An exercise for you}