当前位置: 技术问答>linux和unix
请问线程中的信号量,怎么设置成0,1信号量?
来源: 互联网 发布时间:2015-01-22
本文导语: 书上的例子是通用信号量,信号量可以多值,比如可以取2,3,4。。。。 我现在只想要二进制的信号量,怎么设置? | to ari: the manual means that once you call sem_post too many times, it MIGHT rea...
书上的例子是通用信号量,信号量可以多值,比如可以取2,3,4。。。。
我现在只想要二进制的信号量,怎么设置?
我现在只想要二进制的信号量,怎么设置?
|
to ari:
the manual means that once you call sem_post too many times, it MIGHT reach the maximum value allowed by the implementation of the semaphore, not just means the maximum value the programmer intending to limit.
to hsubo:
I think you cannot expect the underlying implementation to provide you any mechanism to limit the minimum or maximum value the semaphore can hold. You MUST add in your own logic to achieve such aims, that is, as the programmer, you should guarantee only one sem_post are called after a sem_wait operation and vice versa.
the manual means that once you call sem_post too many times, it MIGHT reach the maximum value allowed by the implementation of the semaphore, not just means the maximum value the programmer intending to limit.
to hsubo:
I think you cannot expect the underlying implementation to provide you any mechanism to limit the minimum or maximum value the semaphore can hold. You MUST add in your own logic to achieve such aims, that is, as the programmer, you should guarantee only one sem_post are called after a sem_wait operation and vice versa.
|
建议你
man sem_post
===========================
The sem_post function sets errno to the following error code on error:
ERANGE after incrementation, the semaphore value would exceed SEM_VALUE_MAX (the semaphore count is left unchanged in this case)
man sem_post
===========================
The sem_post function sets errno to the following error code on error:
ERANGE after incrementation, the semaphore value would exceed SEM_VALUE_MAX (the semaphore count is left unchanged in this case)