[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
maybee error in sem_getvalue funktion
Hi
I have tested the sem_getvalue funktion.
Program.
#include <rtl.h>
#include <rtl_fifo.h>
#include <time.h>
#include <rtl_sched.h>
#include <rtl_sync.h>
#include <pthread.h>
#include <posix/unistd.h>
#include <semaphore.h>
int init_module(void) {
sem_t sem;
int res,val,semres;
semres = sem_init(&sem,0,1);
res = sem_getvalue(&sem,&val);
rtl_printf("TEST sem val %d res %d semres %d \n",val,res,semres);
semres = sem_post(&sem);
res = sem_getvalue(&sem,&val);
rtl_printf("TEST sem val %d res %d semres %d \n",val,res,semres);
semres = sem_wait(&sem);
res = sem_getvalue(&sem,&val);
rtl_printf("TEST sem val %d res %d semres %d \n",val,res,semres);
sem_destroy(&sem);
return 0;
}
void cleanup_module(void) {
}
I get the result.
May 20 14:33:19 xterm39 kernel: TEST sem val -1070961824 res 1 semres 0
May 20 14:33:19 xterm39 kernel: TEST sem val -1070961824 res 2 semres 0
May 20 14:33:19 xterm39 kernel: TEST sem val -1070961824 res 1 semres 0
the return value res from sem_getvalue states the value of the
semaphore. this should be 0 or positiv so this is allright. But the
value of the semaphore is wrong (here val). this should state the value
of the semaphore according to the POSIX standard.
Have there been made any changes to the POSIX standard? (or is this
caused by calling sem_getvalue from init_module?)
Anders Gnistrup.