Re: My try/catch block isn't catching exceptions on 10.6
Re: My try/catch block isn't catching exceptions on 10.6
- Subject: Re: My try/catch block isn't catching exceptions on 10.6
- From: Michael Ash <email@hidden>
- Date: Sat, 28 Nov 2009 23:58:27 -0500
On Fri, Nov 27, 2009 at 2:40 PM, Mark Allan <email@hidden> wrote:
>
> On 27 Nov 2009, at 1:10 am, Dave Keck wrote:
>>>
>>> Exception Type: EXC_BAD_ACCESS (SIGBUS)
>>
>> After a cursory reading of your code it looks like you're dealing with
>> a threading issue involving myItemList or imminentList. Your comment
>> mentions "We don't really care if imminentList changes because the
>> dictionary object will always be there even if the contents aren't."
>> Does this mean you're modifying imminentList from one thread while
>> another is attempting to read from it? If so, you need a lock around
>> the reads and writes.
>
> Isn't it the case that you only need locks around something if you plan that
> it will be modified by more than one thread at a time, or if you write to it
> in another thread and care that any read operation will be predictable?
No, you need locks around something if it will be accessed *in any
way* by another thread while one thread is modifying the data
structure.
Think about a really simple array implementation. When you add a new
object, it allocates new memory, copies the array contents over, and
then frees the old one. If you have one thread doing this while
another thread is reading, it could end up reading in that newly-freed
memory, causing a crash.
NSMutableDictionary is doing something similar, but more complex. You
can't read and write simultaneously, even if you're only writing from
one thread at once. If your code currently allows this, you must
change it if you want to have any shot at reliability.
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