• 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: Accessing array in thread safe way
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing array in thread safe way


  • Subject: Re: Accessing array in thread safe way
  • From: Kyle Sluder <email@hidden>
  • Date: Thu, 08 Mar 2012 15:53:02 -0800

On Mar 8, 2012, at 2:15 PM, Quincey Morris wrote:

> On Mar 8, 2012, at 12:18 , CoGe - Tamas Nagy wrote:
>
>> I should subclass NSMutableArray because I had a project which used NSMutableArray (calls) before, but was not thread safe. Anyway, I can't really understand why it would be _really_ better to implement just accessors, but maybe you could explain it a bit more?
>
> Well, slap my head if I'm missing your intention, but I don't see how having an *atomically* safe NSMutableArray helps at all. As soon as anyone in any thread writes:
>
> 	for (NSInteger i = 0; i <= atomicallySafeArray.count; i++) {
> 		id object = [atomicallySafeArray objectAtIndex: i];
> 		...
> 	}
>
> or any such construct that contains 2+ references to the array that might see a different state of the array over time, then the code is broken and not thread safe. This is also broken:
>
> 	for (id object in atomicallySafeArray)
> 	…
>
> for the separate but related reason that fast enumeration will fail if the array mutates.
>
> Also, implementing the accessors won't solve either of these problems.
>
> Thread safety does *not* come from atomicity. Conversely, in many cases atomicity has no value whatsoever -- because thread safety is what's really required.

And this is why atomic-by-default is a misfeature. Slower code that contributes to a false impression of thread-safety.

--Kyle Sluder
_______________________________________________

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: 
 >Accessing array in thread safe way (From: "Jan E. Schotsman" <email@hidden>)
 >Re: Accessing array in thread safe way (From: Charles Srstka <email@hidden>)
 >Re: Accessing array in thread safe way (From: "Jan E. Schotsman" <email@hidden>)
 >Re: Accessing array in thread safe way (From: CoGe - Tamas Nagy <email@hidden>)
 >Re: Accessing array in thread safe way (From: Charles Srstka <email@hidden>)
 >Re: Accessing array in thread safe way (From: CoGe - Tamas Nagy <email@hidden>)
 >Re: Accessing array in thread safe way (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Accessing array in thread safe way
  • Next by Date: String Constants the solution
  • Previous by thread: Re: Accessing array in thread safe way
  • Next by thread: Re: Accessing array in thread safe way
  • Index(es):
    • Date
    • Thread