• 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: Thread-safe atomic property for array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thread-safe atomic property for array


  • Subject: Re: Thread-safe atomic property for array
  • From: Sandy McGuffog <email@hidden>
  • Date: Sat, 15 Aug 2015 14:21:55 +0200

What guarantees that the current autorelease cycle doesn’t end in the middle of this code?

Actually, as I think about it, technically, the [[hostObject myArray] retain] should be wrapped in some kind of lock mechanism itself to make it atomic….


> On Aug 15, 2015, at 2:10 PM, Mike Abdullah <email@hidden> wrote:
>
>
>> On 15 Aug 2015, at 13:07, Sandy McGuffog <email@hidden> wrote:
>>
>>
>>> On Aug 15, 2015, at 1:14 PM, Mike Abdullah <email@hidden> wrote:
>>>
>>> NSArray *array = [hostObject myArray];
>>> // run your checks, etc.
>>> NSString *someString = [array objectAtIndex:2];
>>
>> Just to be safe:
>>
>> NSArray *array = [[hostObject myArray] retain];
>> // run your checks, etc.
>> NSString *someString = [array objectAtIndex:2];
>> [array release];
>>
>> Or whatever other way of ensuring the array isn’t dealloced out from under you, depending on how you’re doing memory management
>
> No need. The OP has stated myArray is an atomic property. It’s guaranteed not to go away until the end of the current autorelease pool.
>
> If the above code did actually add some protection, it would mean the first line of code had a race condition in it where you might not be able to retain in time. You’d just be hiding the problem and making it less likely, rather than actually fixing it.


_______________________________________________

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: Thread-safe atomic property for array
      • From: "Clark S. Cox III" <email@hidden>
    • Re: Thread-safe atomic property for array
      • From: Mike Abdullah <email@hidden>
References: 
 >Thread-safe atomic property for array (From: Trygve Inda <email@hidden>)
 >Re: Thread-safe atomic property for array (From: Mike Abdullah <email@hidden>)
 >Re: Thread-safe atomic property for array (From: Sandy McGuffog <email@hidden>)
 >Re: Thread-safe atomic property for array (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: Automatically activate next window after one is closed
  • Next by Date: Re: Thread-safe atomic property for array
  • Previous by thread: Re: Thread-safe atomic property for array
  • Next by thread: Re: Thread-safe atomic property for array
  • Index(es):
    • Date
    • Thread