Question about pthread_process_shared attribute - Unix

This is a discussion on Question about pthread_process_shared attribute - Unix ; For interprocess synchronization mutexes, it seems some implementations of posix threads support a PTHREAD_PROCESS_SHARED flag, which can be used so that a mutex can work between processes, rather than only between threads. I have two questions about this: 1: In ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Question about pthread_process_shared attribute

  1. Question about pthread_process_shared attribute

    For interprocess synchronization mutexes, it seems some
    implementations of posix threads support a PTHREAD_PROCESS_SHARED
    flag, which can be used so that a mutex can work between processes,
    rather than only between threads.

    I have two questions about this:

    1: In order for inter-process synchronization to work, does the
    pthread_mutex_t object need to be placed in shared memory?

    2: What is the advantage/difference between using a shared mutex and
    using posix semaphores. (Note, I'm not asking about System V
    semaphores, which are annoying to use, but rather posix semaphores,
    i.e. semaphores which use the sem_wait/sem_post system calls)

    Thanks.


  2. Re: Question about pthread_process_shared attribute

    chsalvia@gmail.com wrote On 10/15/07 08:07,:
    > For interprocess synchronization mutexes, it seems some
    > implementations of posix threads support a PTHREAD_PROCESS_SHARED
    > flag, which can be used so that a mutex can work between processes,
    > rather than only between threads.
    >
    > I have two questions about this:
    >
    > 1: In order for inter-process synchronization to work, does the
    > pthread_mutex_t object need to be placed in shared memory?


    Suppose the mutex resides in Process P's private
    memory, not shared with other processes. Now explain
    how Process Q locks and unlocks a mutex that it can't
    get access to, that it can't even see.

    "It was on display in the bottom of a locked filing
    cabinet stuck in a disused lavatory with a sign on
    the door saying `Beware of the Leopard'." -- HHGttG

    --
    Eric.Sosman@sun.com

  3. Re: Question about pthread_process_shared attribute

    chsalvia@gmail.com wrote:

    > 1: In order for inter-process synchronization to work, does the
    > pthread_mutex_t object need to be placed in shared memory?


    Of course. How would the other process(es) see it otherwise?

    > 2: What is the advantage/difference between using a shared mutex and
    > using posix semaphores.


    Mutexes have binary state, which can more explicitly reflect the desires
    of the programmer. It also allows some small performance optimizations
    as compared with a counting semaphore. They also have the concept of an
    owner, which can be both good and bad, as it introduces problems if the
    owner dies while holding the mutex. Robust mutexes were designed to
    handle that case, but they have their own gotchas.

    Chris

+ Reply to Thread