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

  • From: Rene Gollent <anevilyak@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 14 Sep 2009 17:52:23 -0500

On Mon, Sep 14, 2009 at 5:34 PM, Ryan Leavengood <leavengood@xxxxxxxxx> wrote:
> - Using be_app_messenger.SendMessage(B_QUIT_REQUESTED) to quit the app
> is fine, but I generally see be_app->PostMessage(B_QUIT_REQUESTED)

be_app_messenger is indeed safer but *most* of the time it won't
matter. The main reason the messenger is safer is it can check the
looper list to ensure that the target is in fact valid before sending
the message, whereas the PostMessage variant more or less assumes the
app pointer is still valid. In the majority of cases this will be true
since the app is generally the last thing to exit, but especially if
you're using threads of your own that you've spawned outside of the
ones belonging to the loopers, that's not guaranteed depending on when
you terminate such a thread. In general it's good practice to avoid
using PostMessage directly on anything that's not attached to the same
looper as the caller, so I'd discourage even suggesting the
PostMessage variant above.

Regards,

Rene

Other related posts: