I am having difficulty with my IPC producer consumer program.
Code:
if ((shmid=shmget(KEY, sizeof(struct shseg), IPC_CREAT|0666|IPC_EXCL ==-1){
if (errno==EEXIST) {
}
}
This code checks too see if the shared memory segment is in exclusive mode, if it is it should return the EEXIST error. Not sure if my syntax is correct in the if statment as it seems to create error not seen in the program without it.
Code:
int simshm(void) {
int shmid;
int mutex,uflo,oflo;
shmid=shmget(KEY, sizeof(struct shseg), IPC_CREAT|0666);
ashseg=(struct shseg *) shmat(shmid, 0, 0); // follow initsem logic
mutex=initsem(MUTEX,1);
oflo=initsem(OFLO, 3);
uflo=initsem(UFLO,0);
printf("%d %d %d\n", mutex,oflo,uflo);
while (1) {
p(uflo);
p(mutex);
printf("con in\n");
printf("con: %c\n",ashseg->buffer[ashseg->out]);
ashseg->out=(ashseg->out + 1) % BUFSIZE;
v(mutex);
v(oflo);
printf("con out\n");
sleep(1);
}
return 1;
}