How to use mutex between processes

The example in the docs shows how to use a mutex between threads in a
single process, but I want to use it to control access to a resource by
two different processes. How does the kernel know that the processes
are trying to lock the same mutex? I don’t see anything about
registering the name of the mutex, or ??? Thanks.

I would assume that all you would need to do is create the mutex in
shared memory, if you wanted to share it between processes. If you want
a mutex across a LAN you can use a named semaphore. I generally use
semaphore’s between processes, no particular reason, just habit.

-----Original Message-----
From: Bruce Davis [mailto:bruce.r.davis@boeing.com]
Posted At: Tuesday, March 27, 2001 4:23 PM
Posted To: os
Conversation: How to use mutex between processes
Subject: How to use mutex between processes


The example in the docs shows how to use a mutex between threads in a
single process, but I want to use it to control access to a resource by
two different processes. How does the kernel know that the processes
are trying to lock the same mutex? I don’t see anything about
registering the name of the mutex, or ??? Thanks.

In other POSIX systems (SGI IRIX) I’ve done what you suggest (mutex in
shared memory) and it works just fine. I’ll try in QRTP, but I suspect with
their POSIX orientation it should work fine also. I was interested by your
suggestion of using a semaphore across the net. Is that POSIX or QNX (I’m
new to QNX/QRTP)

Rennie Allen wrote:

I would assume that all you would need to do is create the mutex in
shared memory, if you wanted to share it between processes. If you want
a mutex across a LAN you can use a named semaphore. I generally use
semaphore’s between processes, no particular reason, just habit.

-----Original Message-----
From: Bruce Davis [mailto:> bruce.r.davis@boeing.com> ]
Posted At: Tuesday, March 27, 2001 4:23 PM
Posted To: os
Conversation: How to use mutex between processes
Subject: How to use mutex between processes

The example in the docs shows how to use a mutex between threads in a
single process, but I want to use it to control access to a resource by
two different processes. How does the kernel know that the processes
are trying to lock the same mutex? I don’t see anything about
registering the name of the mutex, or ??? Thanks.

John H. Zouck
The Johns Hopkins University
Applied Physics Laboratory

“John H. Zouck” <john_zouck@jhuapl.edu> wrote in message
news:3AC1FF7C.4FDECC8B@jhuapl.edu

In other POSIX systems (SGI IRIX) I’ve done what you suggest (mutex in
shared memory) and it works just fine. I’ll try in QRTP, but I suspect
with
their POSIX orientation it should work fine also. I was interested by your
suggestion of using a semaphore across the net. Is that POSIX or QNX (I’m
new to QNX/QRTP)

I believe that named semaphores are Posix (but I could be wrong). The fact
that you can access them across the net, however, is a function of QNX’s
network transparency. For more information see sem_open in the docs.

Rennie

Bruce Davis <bruce.r.davis@boeing.com> wrote:

The example in the docs shows how to use a mutex between threads in a
single process, but I want to use it to control access to a resource by
two different processes. How does the kernel know that the processes
are trying to lock the same mutex? I don’t see anything about
registering the name of the mutex, or ??? Thanks.

The mutex must be created in memory both processes can see, that is,
in a shared memory area.

The mutex must have the process shared attribute flag set – see
pthread_mutexattr_setpshared() in the docs.

-David

QNX Training Services
dagibbs@qnx.com