• 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: Thu, 31 May 2012 18:45:43 +0100

On 31 May 2012, at 17:14, Scott A Andrew wrote:

> My guess is that you are crashing because kMyVLFContext is not an objective C object. According to the Apple documentation (https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocThreading.html#//apple_ref/doc/uid/TP30001163-CH19-SW1):
>
> The @synchronized() directive takes as its only argument any Objective-C object, including self. This object is known as a mutual exclusion semaphore or mutex. It allows a thread to lock a section of code to prevent its use by other threads. You should use separate semaphores to protect different critical sections of a program. It’s safest to create all the mutual exclusion objects before the application becomes multithreaded, to avoid race conditions.
>
> My guess is that ARC is trying to do a bit of memory management on your context pointer and the calls it expects aren't there.

Ok, that seems to make sense. At any rate, changing kMyVLFContext to a more regular style (an NSString) seems to fix the issue.
static NSString *kMyVLFContext = @"kMyVLFContext";

Thanks,
António

> Scott
>
> On May 31, 2012, at 8:47 AM, Antonio Nunes wrote:
>
>> I have a function that looks essentially like this:
>>
>> static void *kMyVLFContext = &kMyVLFContext;
>> Boolean myFunction(CFURLRef path)
>> {
>> 	CFDictionaryRef myDictionary = NULL;
>>
>> 	@synchronized(kMyVLFContext) {
>> 		… work …
>> 	}
>>
>> 	return myDictionary != NULL;
>> }
>>
>> This function works fine with manual memory management. After compiling with ARC though, a crash occurs on line "@synchronized(kMyVLFContext) {". I wouldn't think this should be affected by ARC at all. Any hints as to what might be afoot here, or is it more likely something else, earlier on is causing a failure here (e.g. stomping kMyVLFContext)?
>>
>> Removing the lock causes the function to return successfully, but may of course cause issues on occasions when the function is called from several threads at once.
>>
>> -António
>>
>> ----------------------------------------------------
>> It isn't so important to do great things,
>> as to do what you do with great love.
>> ----------------------------------------------------
>>
>>
>>
>>
>> _______________________________________________
>>
>> 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
>

-----------------------------------------------------------
And could you keep your heart in wonder
at the daily miracles of your life,
your pain would not seem less wondrous
than your joy.

--Kahlil Gibran
-----------------------------------------------------------



_______________________________________________

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


References: 
 >@synchronized crashing with ARC (From: Antonio Nunes <email@hidden>)
 >Re: @synchronized crashing with ARC (From: Scott A Andrew <email@hidden>)

  • Prev by Date: Re: Sandboxing. WTF?
  • 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