CS-Base
CS-Base copied to clipboard
图解系统5.2对于信号量PV操作的具体过程说明有误
问题段落:https://xiaolincoding.com/os/4_process/process_commu.html#%E4%BF%A1%E5%8F%B7%E9%87%8F
// pseudo code from https://www.scaler.com/topics/operating-system/semaphore-in-os/
P(semaphore){
if semaphore is greater than 0
then decrement semaphore by 1
}
V(semaphore){
increment semaphore by 1
}
信号量应该始终是一个非负值,不存在等于-1的情况
sem_wait() decrements (locks) the semaphore pointed to by sem. If the semaphore's value is greater than zero, then the decrement proceeds, and the function returns, immediately. If the semaphore currently has the value zero, then the call blocks until either it becomes possible to perform the decrement (i.e., the semaphore value rises above zero), or a signal handler interrupts the call.
glibc中的源码: sem_post(P操作) sem_wait(V操作) sem_wait_fast(非阻塞)和sem_wait_slow(阻塞)