• 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: @synchronized crashing with ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @synchronized crashing with ARC


  • Subject: Re: @synchronized crashing with ARC
  • From: Antonio Nunes <email@hidden>
  • Date: Fri, 01 Jun 2012 04:59:43 +0100

On 1 Jun 2012, at 02:34, Charles Srstka wrote:

> static dispatch_once_t onceToken;
> dispatch_once(&onceToken, ^{
> 	myVLFContext = [[VLFContext alloc] init];
> });
>
> @synchronized(myVLFContext) {
> 	...
> }

That does seem better. Any reason though to create a custom class? Couldn't we just [[NSObject alloc] init]? I think @synchronized cares about pointer uniqueness, not about the class, no? (And, as I learned from this, under ARC the pointer should also actually respond to memory management methods, i.e. be a real object, which is satisfied simply by it pointing to an object of class NSObject.)

> If you keep having trouble with @synchronized, though, I’d recommend just switching to a pthread_mutex_t, a spin lock, or dispatch_sync. Any of these should have better performance than @synchronized anyway.

I'd already solved the issue with @synchronized, but am indeed considering switching to pthread_mutex_t or dispatch_sync, although I think the practical performance gains will be marginal.

-António

----------------------------------------------------
Energy is like a muscle,
it grows stronger through being used.
----------------------------------------------------



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: @synchronized crashing with ARC
      • From: Charles Srstka <email@hidden>
References: 
 >Re: @synchronized crashing with ARC (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: NSXMLParser thread safe?
  • Next by Date: Re: @synchronized crashing with ARC
  • Previous by thread: Re: @synchronized crashing with ARC
  • Next by thread: Re: @synchronized crashing with ARC
  • Index(es):
    • Date
    • Thread