• 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 10:12:37 +0100

El 5/12/2006, a las 10:06, Chris Suter escribió:

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

You're getting confused.

static id foo = nil;

foo is a pointer and it's value is nil. It's the value that counts, not the location of the variable foo.

@synchronized (foo)

is equivalent to

@synchronized (nil)

- Chris

Thanks a lot of the clarification. I thought that @synchronized worked as though you'd written @synchronized(&foo), but I guess the syntactic sugar doesn't go that far!


Thanks again.

_______________________________________________

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

  • Prev by Date: Re: Synchronizing Thread Execution
  • 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