• 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: Synchronizing Thread Execution
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synchronizing Thread Execution


  • Subject: Re: Synchronizing Thread Execution
  • From: leenoori <email@hidden>
  • Date: Tue, 5 Dec 2006 09:58:05 +0100

El 5/12/2006, a las 2:04, Scott Ribe escribió:

// single static variable shared by all instances:
static id foo = nil;

Not good. Whether it uses some methods of NSObject and fails right away, or
whether it just uses the pointer to access a lock via hash and fails after
you try this with a second variable in some other class. But this should be
fine:


static id foo = [[NSObject alloc] init];

El 5/12/2006, a las 5:18, Scott Ribe escribió:
I gave it a shot and tried different variations of how and where the
variable was instantiated, but the results did not improve upon the
usage of @synchronized(self).

You need a single variable, instantiated only once with a single object, at
some well-defined init/startup time. Are you sure you tried that?

Are you sure that it has to be a "instantiated" variable? I thought that any pointer at all would do; ie. in my example the variable "static id foo" is a unique pointer to a single location in memory, and it doesn't matter that the contents of the memory pointed to by the pointer is nil. @synchronized does not interact with the object in any way, doesn't send it any messages, at least as far as I know, so why would it have to be initialized? In fact, I thought that it didn't even need to be an Objective-C object; any pointer will do. I believe this is the way pthread mutexes works as well (and @synchronized uses pthread mutexes under the hood, right?), and pthread mutexes certainly don't know or care about what an Objective- C object is. I may be misunderstanding this, and if so I'd like to correct any misconceptions I might have.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Synchronizing Thread Execution
      • From: Scott Ribe <email@hidden>
    • Re: Synchronizing Thread Execution
      • From: Chris Suter <email@hidden>
References: 
 >Re: Synchronizing Thread Execution (From: Scott Ribe <email@hidden>)

  • Prev by Date: RE: Text Caret -- Focus Ring Interference
  • Next by Date: Re: Synchronizing Thread Execution
  • Previous by thread: Re: Synchronizing Thread Execution
  • Next by thread: Re: Synchronizing Thread Execution
  • Index(es):
    • Date
    • Thread