[interfacekit] Re: App Registration

On Tue, 23 Jul 2002, Ingo Weinhold wrote:

> BRoster::xLaunchAppPrivate()
> * call BRoster::AddApplication() for pre-registration
>   - if the app is single/exclusive launch and already runnning, send
>     B_ARGV/REFS_RECEIVED and other messages straight to it and return
> * call load_image()
>   - if it fails, call BRoster::RemovePreRegApp() and return
> * send B_REFS_RECEIVED/other messages and B_READY_TO_RUN to the new
>   application

One detail is missing here. Directly after a successful load_image(), the
registrar has to be told the team ID of the pre-registered app, using
BRoster::SetTeam() or BRoster::SetTeamAndThread() (I don't have the header
at hand right now).

Why? Well, if two instances of the application are launched at about the
same time, one via BRoster::Launch() the other one via system() or
whatever, then the right instance must be told that it is pre-registered,
otherwise trouble is guaranteed.

This raises another problem. There is, once again, a race condition in the
process. Once load_image() has been called, the launched application has
its own will and there is no warranty that it won't call
BRoster::IsAppPreRegistered() before the first application was able notify
the roster about the team ID of the pre-registered app.

The only solution I currently see, is to postpone the (roster side)
processing of the IsAppPreRegistered() request until all pre-registered
instances of the enquiring app have been assigned a team ID. Or at least
until the team ID in question has been assigned to an instance. This can
be done relatively easily using the BLooper::DetachCurrentMessage()
feature.

I think, it is a good idea to add some regular sanity checks to the
registrar. E.g. one that once a second or so verifies that the teams of
the listed (pre-)registered applications are still running, and which
removes those that aren't (and all associated message runners).
Furthermore pre-registered apps without a team ID assigned, should be
removed after a certain amount of time (a minute maybe), or as soon as
the launching  team has gone. During my experiments I must have managed to
kill one of the apps at a critical moment and thereafter I was unable to
start them anymore. They were blocking in BRoster::IsAppPreRegistered()
waiting for a reply. I had to reboot to continue the tests. Regular sanity
checks are a Good Thing (tm).

If someone sees problems in my process layout, please don't hesitate to
share them with me. :-)

CU, Ingo


Other related posts: