[haiku-development] Re: Haiku "Hello, World" tutorial

  • From: Rob Hoelz <rob@xxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 15 Sep 2009 08:19:11 -0500

Stephan Aßmus <superstippi@xxxxxx> wrote:
> Jonas Sundström schrieb:
> > Rene Gollent <anevilyak@xxxxxxxxx> wrote:
> >> On Mon, Sep 14, 2009 at 6:28 PM, Ryan Leavengood <
> >> leavengood@xxxxxxxxx> wrote:
> >>> Yeah that makes sense but I'm pretty sure I've seen the
> >>> PostMessage version used a lot more than the SendMessage one.
> >>> Maybe we need to update some code then ;)
> >> Just checked....not sure if this was the case in BeOS or not, but
> >> Haiku's PostMessage implementation also checks the looper list,
> >> which I didn't think it did. Ergo, it's just as safe as
> >> SendMessage.
> > 
> > Shouldn't intra-thread calls between BLooper threads (BWindow and
> > BApplication) be wrapped in Lock() and Unlock() in the usual case?
> > 
> > Is there anything wrong about these assumptions?:
> > 
> > - be_app_messenger is called without locking,
> > being a pointer to a BMessenger
> > 
> > -  be_app being a pointer to a BApplication (a BLooper subclass
> > and thus running in a thread of its own) is not safe to call
> > methods on without first locking. (and unlocking afterwards)
> 
> If you had to lock the other looper, wouldn't that totally render 
> message passing useless? :-}
> 
> Indeed, PostMessage() and SendMessage() are synonymous. Just look at
> the PostMessage() implementation. You don't need to lock (it blocks
> on the message queue lock if the other looper is in your team, which
> is an inner lock just for the queue). PostMessage()/SendMessage()
> also makes sure that the looper is not already gone, by using a
> global BLooper list, which is also protected by an inner lock.
> 
> The preferred way to make an application quit when the window is
> closed is to add a window flag: B_WINDOW_QUIT_ON_CLOSE IIRC. That
> makes better use of existing code. Though for a tutorial, when it
> doesn't already demonstrate message passing elsewhere, it's fine to
> show how to post a message. :-)
> 
> Best regards,
> -Stephan
> 

I remember reading about that flag in the Be Book, but if memory serves
it's unimplemented (at least on BeOS; I wouldn't know about Haiku).

-Rob


Other related posts: