Hi all. I'm using semaphore for processes.
Here a simple code:
In man semctl page I read:Code:... //include declarations ... union semun { int val; struct semid_ds* buf; unsigned short * array; struct seminfo* __buf; }; int main() { //allocating&init semaphore int sem_id; union semun argument; unsigned short int values[1]; values[0] = 12; argument.array = values; semget(IPC_PRIVATE,1,IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR); semctl(sem_id,0,SETALL,argument); //at this point the sem value is 12 //now i want read this value ...HOW?... return 0; }
So I write some code like this:GETALL Return semval (i.e., the current value) for all semaphores of the set into arg.array. The argument semnum is ignored. The calling process must have read permission on the semaphore set.
but the function semctl seems to have no effects: in fact the debug line printf prints the same value of the second printf...Code:... union senum arg; //debug line: printf("%d",arg.array[0]); semctl(sem_id,0,GETALL,arg); printf("%d",arg.array[0]);
what's the problem?
thank you!



LinkBack URL
About LinkBacks



why?