sem_getvalue returns the semaphore count, while not setting the actual semaphore counter

Tue Henriksen the@deif.com
Tue Sep 24 12:17:00 GMT 2013


Hi

I have just updated my cygwin installation, which had given me some problems with sem_getvalue function (http://linux.die.net/man/3/sem_getvalue). The prototype is this:

int sem_getvalue(sem_t *sem, int *sval);

On success, it should return 0, otherwise -1. However, it looks like the function lately has been changed so it now returns the semaphore count, and leaves '*sval' unchanged. Please see the example below:


#include <stdio.h>
#include <semaphore.h>

int main(void)
{
   int retval;
   int sema_value = 1234;
   sem_t sema;
   
   printf("sem_getvalue test\n");
   
   retval = sem_init(&sema, 0, 7);
   printf("sema initialized - count has been set to 7 (return value: %d)\n", retval);
   retval = sem_getvalue(&sema, &sema_value);
   printf("sema count is %d (return value: %d)\n", sema_value, retval);

   retval = sem_post(&sema);
   printf("sema post (return value: %d)\n", retval);
   retval = sem_getvalue(&sema, &sema_value);
   printf("sema count is %d (return value: %d)\n", sema_value, retval);
   
   return 0;
}

The output to stdout looks like this:

sem_getvalue test
sema initialized - count has been set to 7 (return value: 0)
sema count is 1234 (return value: 7)
sema post (return value: 0)
sema count is 1234 (return value: 8)

As you can see, the return value is identical to the semaphore count, while the variable that should hold the count, remains unchanged.

This has previously worked ok, but broke after the update today (2013/09/24). My previous update was performed 2013/07/02.

Best regards

Tue Henriksen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 77476 bytes
Desc: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20130924/f87d5647/attachment.obj>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list