On Sun, Jun 15, 2008 at 8:46 PM, Bill Bumgarner <[EMAIL PROTECTED]> wrote:

> I would highly recommend that you look long and hard at how are you are
> managing the data structures that are also used by NSOutlineView.  In
> particular, if you are futzing with an NSMutableArray from one thread while
> the AppKit is enumerating it in another, that can be very problematic.   In
> particular, NSMutableArray may effectively realloc() its contents as it
> crosses certain capacity thresholds.  If the other thread happens to be in
> the middle of reading from the old buffer at that time, well... *boom*.
>

Thanks for the good example of a specific threading issue. In my case, the
outlineview is using my code as the data source. I can control how I access
the NSMutableArray. I do not enumerate the array in that code. If I wanted
to be safe, I should be ok putting locking around my use of the array since
I'm the one populating it and I'm the one reading it in behalf of the
outlineview. That should be sufficient. The outlineview doesn't have any
other mystical connection to the arrays other than through my data source.

I'm still having heartburn with some things in Cocoa. I came from the Java
world. I was excited to hear about CoreData and bindings and all this high
power stuff. But I ran into threading issues with core data which made it
not practical for my usecase. And I needed more flexibility than is
documented with bindings. So now I've downshifted to using a data source,
which is similar to the normal approach in Java.

Threading is hard for me to comprehend in the objective-c world. In Java,
threading is powerful and relatively simple to implement with simple
relatively consistent rules and many classes which are thread safe. Cocoa
seems to have thrown in the towel on threading and completely leaves it up
to the developer. This leads to solutions earlier proposed to use
performSelectorOnMainThread. That solution reminds me of the ancient Windows
3.0 days on DOS when there was no real threading support and you had to
perform all operations in little chunks so you could go back to the event
loop and see if a more important event had come in.

Threading is powerful. It doesn't need to be as hard as Cocoa has made it.
Java makes it easy. It reminds me of garbage collection. Never have to think
about it in Java. It just works. But in Cocoa, garbage collection was
finally just implemented. Maybe someday they'll go back and do some basic
thinking about threads and make it easier to write thread safe code using
Cocoa. As it stands its a nightmare if something as trivial as an Array
isn't even thread safe.
_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to