• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Singletons and Threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Singletons and Threads


  • Subject: Re: Singletons and Threads
  • From: PGM <email@hidden>
  • Date: Fri, 14 Sep 2007 21:49:55 -0400


+ (MPInterpreter*)sharedInterpreter {

@synchronized(self) {

if (sharedMPInterpreter == nil) {

[[self alloc] init]; // assignment not done here

}

}

return sharedMPInterpreter;

}

You are not assigning the newly inited object to the sharedMPInterpreter, so you are in fact returning nil. Leaving aside the @synchronized bit, I would have written it like this:


+ (MPInterpreter *) sharedInterpreter
{
    static MPInterpreter	*sharedInstance = nil;

    if (sharedInstance == nil)
    {
		sharedInstance = [[[self class] alloc] init];
    }

    return sharedInstance;
}

Cheers, Patrick
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Singletons and Threads
      • From: Chris Hanson <email@hidden>
References: 
 >Singletons and Threads (From: "Randall Wood" <email@hidden>)
 >Re: Singletons and Threads (From: "Clark Cox" <email@hidden>)
 >Re: Singletons and Threads (From: "Randall Wood" <email@hidden>)

  • Prev by Date: SOLVED: Determine pressed keys while dragging FROM OTHER application
  • Next by Date: Re: Singletons and Threads
  • Previous by thread: Re: Singletons and Threads
  • Next by thread: Re: Singletons and Threads
  • Index(es):
    • Date
    • Thread