[NSWI004] a04 - Semaphore wait/trywait inconsistency

Martin Zimen zimenm at seznam.cz
Sat Nov 28 20:49:25 CET 2020


Hello,
 I'd like to ask about behavior of sem_wait and sem_trywait. In description 
of sem_wait




> Decrement the value of this semaphore. If the new value would be negative,

> block and wait for someone to call sem_post() first.




Therefore it would block iff the initial value was less or equal to 0. 
However in sem_trywait




>  @retval EBUSY Semaphore has value of 0 and locking would block.




Why shouldn't I return EBUSY when value is negative?

Is there a reason I miss for which these two function behave differently?




Thank you

Martin Zimen


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://d3s.mff.cuni.cz/pipermail/nswi004/attachments/20201128/dec1b82f/attachment.htm>


More information about the NSWI004 mailing list