: I want to use semaphores with process sharing under Linux RH 6.2.
: I'm currently using sem_init() as a POSIX semaphore under a Linux
: system and with a parameter to decide to use process sharing or not.
: It seems that I have some problems with it anyway. I don't know why.
: I've got the information from one source that POSIX semaphores don't
: work with process sharing, is that true?
: This call (sem_init) is described as a POSIX semaphore. Should I use
: the SystemV semaphores (semctl, semop) ?
: Is POSIX semaphores only an API on top of SystemV implementation or is
: it completly different implementation?
: Does somebody know if something changed between RH6.1 (2.2.5) and RH 6.2
: (2.2.14) because my program was working fine with 6.1
: Thanks for your help/time.
POSIX semaphores and SysV semaphores are an entirely different thing.
- POSIX semaphores are implemented in LinuxThreads
- SysV semaphores are in libc core and use syscalls directly
- POSIX semaphores work in multiple threads within one process
- SysV semaphores work over multiple processes
I can't answer whether POSIX semaphores are implemented on top of SysV
semaphores under Linux (don't know LinuxThreads well enough). It may but
it needn't be (e.g. Solaris implements them via different system calls).
When programming semaphores, decide to use one implementation (sem_* is
POSIX, sem* - no underscore - is SysV). You'll surely run into problems
if you mix sem_t (POSIX type) and int (SysV semid type) ...
Because the POSIX stuff is made for thread synchronization (i.e. to be
used within the scope of the same process) it may be required to:
- specify interprocess sharing when creating the semaphore
- sem_init() the semaphore once in each process using it
- creating the semaphore in shared memory.
POSIX semaphores should work between processes provided these three
requirements are met.
Note that RH 6.1 and 6.2 aren't so much different regarding the kernel,
but are profoundly different ('another system' would not be an exaggeration)
with respect to the GNU libc version they use. Pthreads bugs in glibc, esp.
the old buggy versions RH 6.0/6.1 were based on, are not new - maybe you've
written code that broke after the library implemented the correct behaviour ...