I have this code that basically makes a P on the semaphore with number sem
. The semaphore is in a pool. The problem is that sometimes I get Invalid argument
and I can't figure out why.
bool sem_p(key_t key, int sem){
int semid = semget(key, sem, 0666);
struct sembuf sb = {sem, -1, 0};
if(semop(semid, &sb, 1) == -1){
perror("sem p");
printf("sem %d\n", sem);
return FALSE;
}
return TRUE;
}
When that function gets called, it prints
sem p: Invalid argument