Semaphores Flashcards

1
Q

Semaphore

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

acquire()

A

if(counter > 0) then counter–, calling thread continue

if(counter ==0), block the thread on the semaphore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

release()

A

counter++;

if any blocked threads - unblock some such thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Monitor

A

used to achieve mutual exclusion and synchronization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Lock

A

ensures at most one thread in any code that is synchronized on the object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Wait set

A

maintains threads blocked on Monitor; provides coordination;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

wait()

A

suspends calling thread and adds it to Wait set; releases Lock

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

notify()

A

the JVM takes a thread from the wait set and runs it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Purpose of while loop

A

to stop the acquire() function from advancing and exiting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly