[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: patch for NSApplication.m
From: |
Andreas Heppel |
Subject: |
Re: patch for NSApplication.m |
Date: |
Thu, 25 Jul 2002 08:50:14 +0200 |
Hello David,
On Wed, 24 Jul 2002 16:04:49 -0400
"DavidRelson" <relson@osagesoftware.com> wrote:
[text omitted...]
>
> That makes sense, though I think having two assignments to NSApp is
> wrong. If the assignment is to be in -init, then +sharedApplication only
> needs call [[self alloc] init] and doesn't need to assign the value to NSApp.
>
I think the intention was to asign a value to NSApp as soon as possible.
Imagine a situation where two threads call sharedInstance. The way it works now
the dirst thread will set NSApp to a valid value calling [self alloc] and it
will do no harm if the second thread _now_ calls sharedInstance. It will see
the newly created application istead of creating anotrher new one. By using one
statement like [[self alloc init] NSApp will be initialized only after the call
to init (ok, a bit earlier considering the init method).
The whole construction does not really avoid race conditions, though, but
rather requires the application to be 'well behaved'. If I remenber right the
GoF didn't care about this point either (please, coreect me if I'm wrong).
Andreas