Docstoc

SemaphoreAssignment

Document Sample
SemaphoreAssignment Powered By Docstoc
					M. Tech. in Computer Engineering Advanced Operating System Assignment 3
February 17, 2007

1

Theory Questions
1. Discuss the design and implementation of implementation of Unix Semaphore. 2. What are the limitations of semaphore? 3. Why semaphores are implemented as OS mechanisms even though there are some user level solutions? 4. Show that following solution for mutual exclusion problem imposes a strict ordering on processes.
p u b l i c c l a s s Attemp3 implements Lock { i n t turn = 0 ; p u b l i c v o i d re q ues t C S ( i n t i ) { w h i l e ( t u r n == 1− i ) ; // b u sy w ai t }// requ estCS public void releaseCS ( i n t i ){ t u r n = 1− i ; }// r e l e a s e C S } 5. Is there any way that following algorithm can deadlock i.e. keep both processes out of their critical sections at the same time? WHILE ( f l a g [ 1 ] == 1 ) Do n o t h i n g END WHILE flag [0] = 1 // C r i t i c a l S e c t i o n Code flag [0] = 0 // r e m a i n d e r S e c t i o n

1

6. Show that if the P() and V() operations of a binary semaphore are not executed atomically, then mutual exclusion may be violated. 7. Show that a couting semaphore can be implemented using binary semaphores. 8.

2

Programming Assignment
1. The following problem is known as the sleeping barber problem. There is one thread called barber. The barber cuts the hair of any waiting customer. If there is no customer, the barber goes to sleep. There are multiple customer threads. A cutomer waits for the barber if there is any chair left in the barber room. Otherwise, the customer leaves immediately. If there is a chair available, then the customer occupies it. If the barber is sleeping, then the customer wakes the barber. Assume that there are n chairs in the barber shop. Write a Java class for SleepingBarber using semaphores that allows the following methods runBarber(), hairCut. How will you extend your algorithm to work for the barber shop with multiple barbers. 2. Write a monitor for the sleeping babrber problem.

2


				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:228
posted:2/26/2009
language:English
pages:2