semaphores

Hi there,

Could someone please confirm which POSIX semaphore routines should be used for a multiprocess (and not multithreaded) environment?

sys/sem.h definitely works. but the routines, semget, semctl, semop are pretty unwieldy. So, I am looking for an easier way out.

From the man pages it also appears that routines in semaphore.h should work for multiprocesses.

#include <semaphore.h>
int sem_init(sem_t *sem, int pshared, unsigned int value);

The man pages say:
"If the pshared argument has a non-zero value, then the semaphore is shared between processes; in this case, any process that can access the semaphore sem can use sem for performing sem_wait(), sem_trywait(), sem_post(), and sem_destroy() operations."

However, the I am not able to achieve mutual exclusion with this. There are no compilation or runtime errors. The danm thing just doesn't work. Could somebody take a guess what I might be doing wrong?

regards,
Quantum Teleporter

DEC had some awesome on-line documentation. Now HP has it on their web site. Maybe this will help you out.

It sure is a wonderful documentation resource!

Thanks a ton!