For our project we will be implementing semaphore using P() and V() in java. Bef
ID: 3537865 • Letter: F
Question
For our project we will be implementing semaphore using P() and V() in java. Before I can do that I need to understand what TestandSet and Enabling/Disabling interrupts to. I understand test and set alone without the addition of semaphores but I do not understand it when semaphores are being implemented. My knowledge is with Test and Set with two threads for example you have a global variable occupied and it is true if a thread is in its critical section. The thread can enter its critical section based on its local variable mustWait. Now lets say Thread one wants to enter and mustwait=true then it repeatedly calls testandset(mustwait, occupied) until occupied is false. When the other thread sets occupied to false after leaving its critical section, when Thread one calls testandset(mustwait, occupied), occupied would be set to false which is copied into mustwait allowing thread one to enter its critical section.Explanation / Answer
if S>0 S=S-1; Else The thread is placed on the waiting queue. //when it is done executing it calls V(S) which says: If any threads are waiting on S Resume with the next waiting thread in the queue Else S=S+1;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.