Synchronizing Thread Execution
Synchronizing Thread Execution
- Subject: Synchronizing Thread Execution
- From: Antonio Nunes <email@hidden>
- Date: Sun, 3 Dec 2006 22:28:51 +0000
Hi,
Reading through the section on synchronizing thread execution on pp.
88-89 of "The Objective-C Programming Language" documentation, I
would have the following query;
If I read it correctly it is stated that "@synchronized(self)" can be
used to synchronize a method call at the instance level, meaning that
that method for that instance can be executed only by one thread at a
time,
while "@synchronized(NSStringFromSelector(_cmd))" can synchronize a
method by name, stating that no other thread will "be allowed to
execute a different method with the same name until the current
method ends".
As it reads "different method" is it correct that what is meant is
any method by that name regardless of it being the same method in a
different instance of the same class, or a different method in any
instance of a different class?
I have instances of a class that can be called from two threads at
"the same time". For one method I need to ensure it is only executed
by one thread at a time, regardless of which instance of the class is
being called, and from which thread. Am I correct that using
"@synchronized(NSStringFromSelector(_cmd))" would provide precisely
this guarantee?
Thanks,
António
----------------------------------------------------
There is a world of difference between
searching for happiness and choosing
to be happy.
----------------------------------------------------
_______________________________________________
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