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
如果block(thread)
停止thread
执行,它如何返回,何处,何时返回?等待/信号(信号量)如何实现伪代码“工作”?
哪个线程在Wait()
之后启用中断? thread
调用block()
应该不会返回,直到另一个线程调用wakeup(thread)
!
- 但是其他线程如何运行?
- 线程切换发生在哪里?
此代码从何而来? – 2012-03-16 21:04:38
从演讲幻灯片... http://web.cecs.pdx.edu/~walpole/class/cs333/fall2006/slides/5.ppt – 2012-03-16 21:14:39