• 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: Mon, 4 Dec 2006 19:54:36 +0100

El 4/12/2006, a las 15:14, Antonio Nunes escribió:

On 3 Dec 2006, at 23:23, Chris Suter wrote:

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.

That's what I thought too, but after some experimentation it doesn't seem to work, or I am misunderstanding what it means. Using the above expression it seems the objects are being modified from somewhere else while we are in the critical region. Using @synchronized(self) this doesn't happen. But this last expression still doesn't provide enough protection:

Can't you just stick a file-scoped static variable somewhere and @synchronize on that?


eg.

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

@implementation Thing

- (void)method
{
    @synchronized(foo)
    {
        // do something
    }
}

@end

_______________________________________________

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

  • Prev by Date: Re: CFMessagePort problems
  • Next by Date: Re: Deciding whether text should be black or white for a given background color
  • Previous by thread: Re: Synchronizing Thread Execution
  • Next by thread: Re: Synchronizing Thread Execution
  • Index(es):
    • Date
    • Thread