On Fri, Nov 27, 2009 at 2:40 PM, Mark Allan <markjal...@blueyonder.co.uk> 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 (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