Sharing synchronization objects between processes
QNX SDP8.0System ArchitectureDeveloperUser
You can share synchronization objects between threads in different processes, but most objects require extra configuration to work across processes.
The exception is named semaphores (i.e., those created with sem_open()), which are inherently shared between processes by existing in the pathname space. For the other synchronization primitives, the object must exist in memory that is visible to all processes that want to use the object. Usually this means shared memory; for more information, refer to shm_open()).
Unnamed semaphores must be initialized with the pshared (second) parameter in
sem_init()
set to a non-zero value; for example:
sem_init(&semaphore_in_shared_memory, 1, 0);
Mutexes, condvars, reader/writer locks, and barriers must be initialized using an attribute structure
with the PTHREAD_PROCESS_SHARED flag set; for example, for a mutex:
pthread_mutexattr_t mtx_attr;
pthread_mutexattr_init(&mtx_attr);
pthread_mutexattr_setpshread(&mtx_attr, PTHREAD_PROCESS_SHARED);
pthread_mutex_init(&mutex_in_shared_memory, &mtx_attr);
pthread_mutexattr_destroy(&mtx_attr);
Page updated:
