hi to all!
i have a question since my program keeps showing a message which is very annoying.i have asked in several forums but still i havent found a satisfying answer but i just found out about this one,so i hope my problem will get solved!
i have several sets of semaphores which i create and when i try to initialize them it keeps showing that message:

# Semaphore setting value : Invalid argument

the thing is that it started showing that message after a while as before it was ok its really strange.the environment is linux
this is what i do for each set to initialize it:

int SharedMemory::initSet1(){

	union semun arg;
	arg.val = 1;
	for(int i=0;i<l;i++){//l is the number of sems
		if (semctl(sem_set1,i,SETVAL,arg) == -1) {
			perror("# Semaphore setting value ");
			return -1;
		}
	}
	return 0;
}

what could be wrong?

Recommended Answers

All 2 Replies

From the man pages:

EINVAL     Invalid  value  for cmd or semid.  Or: for a SEM_STAT operation, the index 
           value specified  in  semid  referred  to  an array slot that is currently 
           unused.

My guess is that l - wherever it is defined - is not suited to be a control for the loop.

yeah it seems i fixed that now and is ok but still i have a broblem with the delete of the semaphores as

if(semctl(sem_set1,i,IPC_RMID,0)==-1)
cout<<"Failed to delete semaphore"<<endl;

seems not to work!ahhh its too annoying
i have to delete semaphores manually every time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.