Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-20 14:18:28

Anthony Williams wrote:

> Making it work across processes would be tricky --- you would have to
> use a named mutex and named semaphore, and that requires generating
> names known to both the processes involved, but which don't clash
> with the names of any other mutexes or semaphores in the system.
> Initially, the writing flag is clear, the reader count is zero, the
> critical section is unlocked and the semaphore is signalled.

Another problem with the cross process implmentation is
where do you put the read counter? It has to be shared
across your processes.
You could use the shared memory by declaring it with
#pragma data_seg ( ".sdata" ) but it may be tricky.
If one of the read processes terminates unexpectedly,
the counter may never go to zero.

The same is actually true for threads.
If a thread that has a read access exits
unexpectedly, the counter may not decremented.

In the case of the system mutex, the OS takes
care of releasing the mutex that has been
locked by the crashed process/thread.
In particular, the wait function will

Here is how Win32 describes this code.

"The specified object is a mutex object that was not released by the thread that owned the mutex
object before the owning thread terminated. Ownership of the mutex object is granted to the
calling thread, and the mutex is set to nonsignaled."

You would need do something similar for you read counter,
that without a built-in OS support, could be quite tricky.


Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Boost list run by bdawes at, gregod at, cpdaniel at, john at