Re: Synchronizing Thread Execution
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