Bounded Buffer Sema Implementation
var mutex: semaphore = 1 ;mutual exclusion to shared data
empty: semaphore = n ;count of empty buffers (all empty to start)
full: semaphore = 0 ;count of full buffers (none full to start)
wait(empty) ; one fewer buffer, block if none available
wait(mutex) ; get access to pointers
signal(mutex) ; done with pointers
signal(full) ; note one more full buffer
wait(full) ;wait until there’s a full buffer
wait(mutex) ;get access to pointers
<remove item from buffer>
signal(mutex) ; done with pointers
signal(empty) ; note there’s an empty buffer