(20 Points) Jim plans to test out a new idea using a very low-cost wireless stat
ID: 3731879 • Letter: #
Question
(20 Points) Jim plans to test out a new idea using a very low-cost wireless station that he can install outside his dorm room window: users can upload or download their MP3-encoded songs from their laptops, anytime, anywhere on campus. However, the cheap wireless technology he's acquired is half-duplex: all users can either upload or download--never both at once. The following questions investigate your ability to help Jim in particular ways.
(a) (5 Points): Jim intends to test out the basic idea, with just two users, of whom only one can upload or download one song at a time. To impress him, you whip out the following simple semaphore-based synchronization code that only works for two users, along with an explanation of why it works correctly:
(b) (5 Points): Jim's next development step requires that multiple users be able to download songs simultaneously, or upload songs simultaneously. So, you produce new semaphore-based code as follows, with a suitable technical explanation of its workings:
(c) (5 Points): While testing out the "simultaneous" strategy, you sadly discover that bandwidth isn't unlimited. Therefore, you have to limit the number of simultaneous active upload or download users to 100. Your new semaphore-based code follows, with a good explanation of its function:
(d) (5 Points): What synchronization problems remain with your "Step (c)" solution, and how might you solve them?
Explanation / Answer
a)Binary semaphore:-
Binary semaphore is a semaphore which only takes the binary values 0 and 1.
code:-
P(Semaphore s){
while(s==0);
s=s-1;
}
V{Semaphore s){
s=s+1;
}
EXPLANATION:-
Here P is wait where it used to decrement the semaphore value to 0 which has been initiated by value 1.
Since it is Binary semaphore ,we have to initiate the semaphore onluy with 1 or 0.
so if we initiated the semaphore value as 1, it enters into wait process
P(Semaphore s){
while(s==0);
s=s-1;
}
Once it entered it checks for the while condition which is false(1 !=0)
So it comes out of the loop and decrement the semaphore value from 1 to 0 , so that it doesn't allow other process into the critical section to use the shared resource.
So once it completed the process or using the resorce , the process comes out the critical section and while coming out it gives signal to the other processes to use the shared resource (in this case shared resource is songs)
V(Semaphore s){
s=s+1;
}.
So it works correctly , by makiing that mutual exclusion means only 1 process in using the shared resource at a single time and not allowing the other process to use the shared resource which may leads to deadlock.
B)Its like many readers many writers problem..means at a single time many processes are using the shared resource.
So for this we can simply initiate the semaphore value greator than 1 so that other process can alos enter into the critical section ,
P(Semaphore s) #let Semaphore value s=5
while(s==0);
s=s-1;
}
So here p1,p2,p3,p4,p5 can enetr the critical section after that s value becomes to 0 and no more process can enetr the critical section at that instance.
So this is how it works.
c)Simply initiate the semaphore value with 100 so that at a time 100 processes can use the shared resource.
d)Since 100 processes are using the same resourcce it may leads to the process starvation so that least process may not get the sufficient time to proces.It may leads to CONVOY EFFECT which can be easily solved by shortest job first but some it might also leads to Convoy effect in the case of where a 1 st process have a high burst time .So this inturn can be solved by Round robin algorithm.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.