|
Boost Users : |
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-01-30 12:04:20
Lars Hagström wrote:
> Hi,
>
> I am trying to use Boost.Interprocess to get N processes (senders) to
> send data to one receiver through shared memory.
> The receiver has to be the one that initializes the shared memory, so no
> senders can be "let in" before the receiver has completed
> initialization. I can't guarantee the order that the processes are
> starting in.
> To do this I have both the receiver and the senders create_or_open a
> named_semaphore with 0 as initial value.
> The senders then immediately do a wait on the semaphore, but the
> receiver goes ahead and initializes the memory and then does a post on
> the semaphore. This lets the first sender in, which can then initialize
> itself and then do a post on the semaphore and start running. The second
> sender is then let in (because of the post) and it can get going and so on.
I understand.
> This approach works very well if the semaphore has been manually deleted
> from /dev/shm/ or c:\temp\boost_interprocess\, but will not work if
> there is an old semaphore around.
I understand that the semaphore will still have value 0 and other
senders will continue to work fine. Unless a sender crashes in the
initialization and can't post the semaphore, of course. In that case,
you are lost.
When do you have problems, when launching another receiver if the first
one crashes?
> I can get around this on Windows by doing a named_semaphore::remove,
> since that will fail if a process has got it loaded. But this same code
> will not work on linux, since the semaphore will be unlinked and then
> all the processes will be able to delete the semaphore and will then be
> using different semaphores!
I don't understand what you mean here.
> I am used to semaphores working so that if it is opened when noone has
> it loaded it will be initialized to some known value, but this does not
> appear to be the case with Boost.Interprocess semaphores?
Still lost. In theory, if the semaphore is created you initialize it
with a value, if it's already created you get the old value. What do you
mean with "loaded"
I'm afraid I need a bit more information to help. I know I am missing
something ;-)
Regards,
Ion
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