This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Re: FW: sem_getvalue()
The pthreads-win32 implementation never returns a negative
number, only zero or a positive number (i.e. the actual
semaphore value as close as can be determined). I read it as
optional because it could easily be written unambiguously.
However, it would be worth asking the austin group list for
a clarification.
Ross
Blanco Alejandro-EAB005 wrote:
I experienced an unusual return value from sem_getValue(), and traced it back to the actual POSIX spec that is troubling. I had thought this would return a value < 0 if there are threads waiting on the semaphore, where the absolute value is the number of threads waiting. I saw that it was returning 0 when I had a thread waiting. I looked up the spec (http://www.opengroup.org/onlinepubs/009695399/functions/sem_getvalue.html), and it says:
The sem_getvalue() function shall update the location referenced by the sval argument to have the value of the semaphore referenced by sem without affecting the state of the semaphore. The updated value represents an actual semaphore value that occurred at some unspecified time during the call, but it need not be the actual value of the semaphore when it is returned to the calling process.
If sem is locked, then the object to which sval points shall either be set to zero **or** to a negative number whose absolute value represents the number of processes waiting for the semaphore at some unspecified time during the call.
Is it really optional to return the negative number? Does the implementation, at least sometimes, return 0 only?
Alex Blanco