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: Re-entrancy, Thread-safety, Cocoa, and 1.4.1



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

Mark J. Lilback replied:
|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.

Before 10.2, you can post an application-defined event from your non-UI thread to the event queue, an action which is documented to be thread-safe (and is possible in all versions of OS X), and retrieve it by overriding [NSApplication sendEvent]. I believe the same thing can be done with Cocoa-Java; there was a thread not all that long ago on the subject.
The problem of dealing with a non-threadsafe UI has been around, probably, since the NeXTStep days; if it hasn't been dealt with by now, it's not going to be. There are ways to deal with the problem, ways not even particularly difficult. Perhaps its time to stop complaining and just learn how to work with things as they are.

Glen Fisher
_______________________________________________
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.

References: 
 >Re-entrancy, Thread-safety, Cocoa, and 1.4.1 (From: "Mark J. Lilback" <email@hidden>)



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.