Wait(semaphore sem) {
DISABLE_INTS
sem.val--
if (sem.val < 0){
add thread to sem.L
block(thread)
}
ENABLE_INTS
Signal(semaphore sem){
DISABLE_INTS
sem.val++
if (sem.val <= 0) {
th = remove next
thread from sem.L
wakeup(th)
}
ENABLE_INTS
If block(thread)
stops a thread
from executing, how, where, and when does it return?
Which thread enables interrupts following the Wait()
?
the thread
that called block()
shouldn’t return until another thread has called wakeup(thread)
!
- but how does that other thread get to run?
- where exactly does the thread switch occur?