> Careful! Unless you're synchronizing access to the mutable > dictionary, this is not thread-safe. Even if it appears to work in > some cases, it's likely to blow up in your face in real-world use.
Right, in general, but I don't see any problem with the proposed use, since there's adequate synchronization implicitly: - Main thread sets up dictionary, retains it, spawns secondary thread. - 2nd thread retains the dictionary, reads parameters, does its stuff, adds results to the dictionary, releases the dictionary, calls performSelector:onMainThread. - Main thread reads results, releases the dictionary. Note that the retain/release in the 2nd thread is really only necessary if there's a possibility that the main thread will lose interest in the results and release the dictionary before the 2nd thread finishes. Re your caution in particular, the main thread must not "peek" in the dictionary (to look at partial results for instance) before the 2nd thread has called back, because that look into the dictionary could happen in the middle of an update when its internal state is inconsistent. Any attempt to monitor progress would require either explicit synchronization on the dictionary, or more simply just use performSelector:onMainThread: with a new object allocated and set up in the 2nd thread and released on the main thread for each call. And my personal preference would be to return results that way as well, rather than reuse the dictionary, because it doesn't seem simpler in any way to use a single dictionary for both purposes (unless the main thread, after the 2nd thread has finished, would need access to the parameters for UI display or whatever). -- Scott Ribe scott_r...@killerbytes.com http://www.killerbytes.com/ (303) 722-0567 voice _______________________________________________ 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