Semaphores Flashcards
Semaphore
used to control access to a common resource by multiple threads and avoid critical section problems;
supports two atomic operations (acquire and release); never negative
acquire()
if(counter > 0) then counter–, calling thread continue
if(counter ==0), block the thread on the semaphore
release()
counter++;
if any blocked threads - unblock some such thread
Monitor
used to achieve mutual exclusion and synchronization
Lock
ensures at most one thread in any code that is synchronized on the object
Wait set
maintains threads blocked on Monitor; provides coordination;
wait()
suspends calling thread and adds it to Wait set; releases Lock
notify()
the JVM takes a thread from the wait set and runs it
Purpose of while loop
to stop the acquire() function from advancing and exiting