【发布时间】:2015-09-05 03:25:49
【问题描述】:
在一次采访中我被问到...
Wait(semaphore sem) {
DISABLE_INTS
sem.val--
if (sem.val < 0){
add thread to sem.L
block(thread)
}
ENABLE_INTS
以上是信号量等待实现(从其他线程复制)。 当多个线程尝试入队时(当它们未能获得锁时),队列 sem.L 如何受到保护?在更新队列之前我们会加锁吗?
【问题讨论】:
标签: multithreading operating-system binary-semaphore