CS-Base icon indicating copy to clipboard operation
CS-Base copied to clipboard

图解系统5.2对于信号量PV操作的具体过程说明有误

Open sora-blue opened this issue 2 years ago • 0 comments

问题段落: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的情况

man7.org关于sem_wait()的说明

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(阻塞)

sora-blue avatar Jul 17 '23 06:07 sora-blue