robertkjr3d
Programmer
Ok I've tried so many things..and I think the overall problem is that I'm just not as familiar with C code as I would like.
I'm useing #include <semaphore.h>
Ok I am declaring these
sem_t *mysemp;
int oflag = (O_CREAT | O_EXCL);
mode_t mode = 0644;
const char semname[] = "/tmp/mysem1";
unsigned int value = 1;
int sts;
Ok in an intialization section I write this code
{
mysemp = sem_open(semname, oflag, mode, value);
}
Ok finally in the routine that has a critical section
{
mysemp = sem_open(semname, 0);
sem_wait(mysemp); // Critical section
//do stuff
sem_post(mysemp);// end critical section
}
There are multiple threads, and two different processes, that must be handled here. However this piece of code, by putting in degug code, I have ascertained that it hangs on the first sem_wait call, like it blocked the first call.
Help me correct this code!
I'm useing #include <semaphore.h>
Ok I am declaring these
sem_t *mysemp;
int oflag = (O_CREAT | O_EXCL);
mode_t mode = 0644;
const char semname[] = "/tmp/mysem1";
unsigned int value = 1;
int sts;
Ok in an intialization section I write this code
{
mysemp = sem_open(semname, oflag, mode, value);
}
Ok finally in the routine that has a critical section
{
mysemp = sem_open(semname, 0);
sem_wait(mysemp); // Critical section
//do stuff
sem_post(mysemp);// end critical section
}
There are multiple threads, and two different processes, that must be handled here. However this piece of code, by putting in degug code, I have ascertained that it hangs on the first sem_wait call, like it blocked the first call.
Help me correct this code!