Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] shared_memory_object constructor with create_only parameter
From: Derek Kivi (derek.kivi_at_[hidden])
Date: 2010-01-27 10:47:37


> Thanks Derek,
> I should have read the manual more carefully.
>
> But nevertheless this behaviour is strange.
> When one process closes the shared memory, it can not be reopened by
> another one? Thus the processes are not independent any more.
>
> Is there a best practice, how to handle this?
> I have only one writing process, but several readers. So I call
> shared_memory_object::remove only when the writer is destroyed. But I
> have to take care, that the readers are destroyed before the writer is
> destroyed, otherwise the memory is not freed.
>
> But what to do if I have several writers, which could open and close
> the
> shared mem, whenever they like to?
>
> How do you handle this?

Hi Philipp,

We had this same question as well. We solved it by keeping an integer reference counter inside the shared memory. We incremented it whenever we created or opened a shared memory object with a given name, and decremented it before deleting a shared memory object with that name. Only when the count was zero would we actually call shared_memory_object::remove to remove that shared memory from the system.

Derek Kivi
ver. QuIC 0707


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net