CMSC 412 |
NOTE 12 |
March 17, 1999 |
NOTE:Semaphore nItem initially 0; // number of items in the buffer Semaphore nSpace initially 0; // number of spaces in the buffer Semaphore mutex initially 1; // protects add_item and remove_item Append( item ) { P( nSpace ); P( mutex ); add_item; V( mutex ); V( nItem ); } Remove( item ) { P( nItem ); P( mutex ); remove_item; V( mutex ); V( nSpace ); }