• 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: Chris Suter <email@hidden>
  • Date: Mon, 4 Dec 2006 10:23:49 +1100

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?

Looking at objc-sync.m (it's OpenSource), specifically the id2data function which is called from objc_sync_enter (which is what the compiler uses when you do @synchronized), it looks like it compares the pointer so it depends whether NSStringFromSelector returns the same pointer for two different invocations with the same parameter and the answer to that is that it currently doesn't seem to. So, no, it doesn't look like it will be synchronised across all classes. This of course assumes that the implementation of NSStringFromSelector isn't going to change.


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?

Yes, it would seem so.

- Chris



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: Antonio Nunes <email@hidden>
References: 
 >Synchronizing Thread Execution (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Synchronizing Thread Execution
  • Next by Date: Bindings Question
  • Previous by thread: Synchronizing Thread Execution
  • Next by thread: Re: Synchronizing Thread Execution
  • Index(es):
    • Date
    • Thread