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



At 4:42 PM -0600 11/13/02, Steve Klingsporn wrote:
This is a guaranteed way to crash the application. One of many ways. I have plenty of other test cases like this which produce unexpected results. I personally believe that rudimentary thread-safety in the UI classes at least is a very good goal to have. Things like chat programs and what-not that will want to have threads for sockets and the like would really enjoy a thread-safe AppKit.

Steve:

This is what I mean by using MVC. You're having Model objects (including your network connection thread) interact directly with View objects. You should be using a Controller object in between the two.

In your example, the Controller object could have a thread-safe queue that the networking thread adds received text to. The main thread could also watch this queue somehow -- by checking it occasionally in a timer, by using a run loop event source (in Objective-C anyway), etc. -- and then updating the interface as appropriate.

Not only does this alleviate the issues with manipulating your application's human interface from within a non-main thread, it also leads to greater modularity of the code overall.

As for "unexpected results," people have repeatedly told you that the AppKit *isn't* thread-safe and that most AppKit objects should only be manipulated via the main thread. What should be unexpected is for the AppKit to *work* when manipulated via a non-main thread.

-- Chris

--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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: Steve Klingsporn <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.