On Sun, May 2, 2010 at 1:50 AM, James Maxwell <jbmaxw...@rubato-music.com> wrote: >> On May 1, 2010, at 21:22, James Maxwell wrote: >> >>> If I drop into the debugger arbitrarily, before the crash, and check this >>> same array, I noticed that it is nicely filled with NSCFNumbers. But, >>> strangely, there are too many. >> >> My guess is that you've still got multiple threads accessing the mutable >> array simultaneously, and that's not thread-safe if one of the accesses is >> changing the array. > > Well, there's only one object that "changes" the array, so I don't know how > this could happen.
It's a common misconception that the only worry with thread safety is avoiding multiple writers. All it takes to crash is a single write, happening simultaneous with a read. A class that's not thread safe will not tolerate this, and can crash. In general, multiple readers is fine, but the moment you make any changes, you MUST not have ANY reads occurring for the duration of the write. Basically, unless you know enough about multithreading to start doing really advanced things (and when I say "really advanced", I mean the sort of level which most people never even reach), you MUST lock (or otherwise protect, e.g. funneling through a single thread, GCD serial queue, etc.) ALL accesses to any shared objects. Mike _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com