This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Attachment: cygcheck.out
Description: cygcheck.out

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]