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?

6 Years
Discussion Span
Last Post by noscimo

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 

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

cout<<"Failed to delete semaphore"<<endl;

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.