pthread_mutex

This is a discussion on pthread_mutex within the Linux Programming forums, part of the Platform Specific Boards category; Do I have to declare a pthread_mutex as an extern so that I may use it in a different program? ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    3

    pthread_mutex

    Do I have to declare a pthread_mutex as an extern so that I may use it in a different program?

    I want to control one program by playing with the mutex in another program.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    First your implementation has to support the _POSIX_THREAD_PROCESS_SHARED option.
    Then you have to create a pthread_mutexattr_t with the PTHREAD_PROCESS_SHARED attribute.
    Then you use some shared memory mechanism to host the actual pthread_mutex_t.

    More info with an implemenation here: http://www.opengroup.org/onlinepubs/...r_destroy.html

    gg

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    3
    I'm using a fast mutex implementation.

    I think I'm running into some race condition - since the processes are running at different rates.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    Are you talking about futex's? Because those are tricky...http://people.redhat.com/drepper/futex.pdf

    Another alternative is a Sys-V or Posix semaphore.

    gg

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    3
    by fast mutex I was referring to the default instantiation of a mutex using P_THREAD_INSTAN.... somthing or the other.

    futexes sound cool, I'll have to dig into that.

    What do you mean by Sys-V?

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    Ah - ok. Futexes are probably a little more "low-level" than what you need.

    To use a pthread_mutex_t across processes, you'll need to follow the steps in my first posting. But it's probably easier to just use a semaphore.

    SYSV is short-hand for, and most commonly refers to "Unix System 5, Release 4". Another common acronym is "SVR4". http://en.wikipedia.org/wiki/SysV

    Semaphores in the SVR4 specification come from <sys/sem.h> and include the functions semctl(), semget(), and semop().

    The Single Unix Specification, aka POSIX, has their own semaphore api from <semaphore.h> and include the functions sem_init(), sem_post(), sem_wait(), sem_destroy(), etc...

    gg

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21