Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re-entrancy, Thread-safety, Cocoa, and 1.4.1



Steve Klingsporn <email@hidden> wrote:
I hope that as part of all this, Cocoa becomes a little more
thread-safe.

I doubt it will. The problem you describe will happen in a Objective-C application, too. Pretty much every GUI framework is like that: Carbon, Cocoa, and Swing. UI updates are done in one thread. Otherwise, locks would have to be used for every UI call, which would have a horrible impact on performance. Instead, it is up to you to make sure the update happens on the main thread. For swing, you'd use SwingUtilities.invokeLater().

In Objective-C, you'd solve this problem by using performSelectorOnMainThread, which is declared on NSObject (and therefore available in pretty much every object). If there isn't a Cocoa-Java equivalent, I'd file a request for one. It is a very handy feature to have, though only available on 10.2.

(I'm using it for the exact situation you describe, updating an NSTextView with data received from a network thread.)

--
__________________________________________________________________________
"They that can give up essential liberty
Mark J. Lilback to obtain a little temporary safety
<email@hidden> deserve neither liberty or safety."
http://www.lilback.com/ -- Benjamin Franklin
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.