Re: crash on altering NSMutableArray
Re: crash on altering NSMutableArray
- Subject: Re: crash on altering NSMutableArray
- From: James Maxwell <email@hidden>
- Date: Sat, 1 May 2010 23:05:30 -0700
Yes, this all makes sense to me. I'm not super advanced, but I do at least understand the idea of keeping reads/writes temporally distinct.
Anyway, it looks like I found the problem. There was a somewhat unnecessary (or at least easily avoidable call) happening to a method that **does** tamper with that array. I worked around it and it hasn't crashed so far. Fingers crossed. I really only need this to work for about the next hour, while I run some tests and finish my paper! ;-)
thanks for your trouble.
J.
On 2010-05-01, at 10:55 PM, Michael Ash wrote:
> On Sun, May 2, 2010 at 1:50 AM, James Maxwell
> <email@hidden> 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 (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
James B Maxwell
Composer/Doctoral Student
School for the Contemporary Arts (SCA)
School for Interactive Arts + Technology (SIAT)
Simon Fraser University
email@hidden
email@hidden
_______________________________________________
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