• 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: Jens Alfke <email@hidden>
  • Date: Fri, 14 Aug 2015 17:08:20 -0700

> On Aug 14, 2015, at 4:59 PM, Trygve Inda <email@hidden> wrote:
>
> How can I do this safely?
>
> The problem here is that if myArray is being replaced in the main thread
> after [hostObject myArray] is called but before objectAtIndex:2 is called,
> than myArray will disappear out from under the caller.

I believe atomic synthesized properties already support this. The getter method retains and autoreleases the object before returning it to the caller, to ensure that it can’t be dealloced before the caller returns (or exits an @autoreleasepool block.)

(Of course this adds a lot of overhead to the getter, which is why some people make all synthesized properties nonatomic unless they need to be thread-safe.)

—Jens
_______________________________________________

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: 
 >Thread-safe atomic property for array (From: Trygve Inda <email@hidden>)

  • Prev by Date: Thread-safe atomic property for array
  • Next by Date: Re: Thread-safe atomic property for array
  • Previous by thread: Thread-safe atomic property for array
  • Next by thread: Re: Thread-safe atomic property for array
  • Index(es):
    • Date
    • Thread