Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Jason implemented his own Semaphore class in Java as follows, but he found his p

ID: 3625587 • Letter: J

Question

Jason implemented his own Semaphore class in Java as follows, but he found his program using this Semaphore class can proceed from some circumstances. Explain Jason's program problem and suggest how you can fix it. public class Semaphore { private int val; private LinkedList waitQueue; public Semaphore ( int initVal ) { val = initVal: waitQueue = new LinkedList ( ) ; } public synchronized void P ( Thread t ) { if ( val = = 0 ) { waitQueue.addLast ( t ) : t.suspend ( ) ; } else val - - ; } public synchronized void V ( ) { if ( waitQueue.size ( ) > 0 ) ( waitQueue.pollFirst ( ) ) .resume ( ) ; else val + + ; } }

Explanation / Answer

Dear, For the given code semaphore class contains two data members val and LinkedList object.But in constructor only one member initialized. The class semaphore must extend Thread class It should also import linkedList class if it is user defined Hope this will help you
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote