[haiku-development] Re: invalid BMessengers

  • From: "Stephan Assmus" <superstippi@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 07 Aug 2008 00:34:16 +0200

-------- Original-Nachricht --------
> Datum: Wed, 06 Aug 2008 23:20:37 +0200 CEST
> Von: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
> An: haiku-development@xxxxxxxxxxxxx
> Betreff: [haiku-development] Re: invalid BMessengers

> Stephan Assmus <superstippi@xxxxxx> wrote:
> > Sorry for replying to myself...
> > 
> > Stephan Assmus wrote:
> > >                 fHandlerToken = (handler
> > >                     ? _get_object_token_(handler) : 
> > > B_PREFERRED_TOKEN);
> > 
> > I just noticed that even the above line requires the BHandler pointer 
> > to be 
> > valid. Hm.
> 
> Why do you think the handler is allowed to be stale if a looper is 
> given?

The only thing you can safely use a BMessenger for is trying to send a message 
to a looper itself, but not any of it's handlers. BMessenger(NULL, looper) is 
safe, but BMessenger(handler, looper) is not safe. I don't think this is very 
nice, even if that would be what was intended for this API.

In the case of the BPathMonitor, the whole problem I am trying to solve is the 
corner case where the BLooper, that someone supplied to receive node monitoring 
messages, may already be gone at the time BPathMonitor::StopWatching() is 
called. I am just now realizing that BLooper does not free it's attached 
BHandlers, it will only remove them from it's list. In that case, at least the 
BHandler pointers will not be stale, so I can use a simpler solution.

Best regards,
-Stephan

Other related posts: