Re: App modal window and secondary thread
Re: App modal window and secondary thread
- Subject: Re: App modal window and secondary thread
- From: Jens Alfke <email@hidden>
- Date: Fri, 19 Mar 2010 15:35:40 -0700
On Mar 19, 2010, at 2:31 PM, Philippe Sismondi wrote:
Right - that's exactly my question - I don't know that I have to do
this while loop. Is starting the thread after the window pops up
enough? Is there anything about *not* waiting for NSApplication to
set this window as its modal window that might cause a problem with
getting input from the window?
You shouldn't be trying to interact with the window at all from a
background thread. Most of AppKit isn't thread-safe, and it's also not
a clean separation of responsibilities. Thread-safe programming is
really, really hard, and the best way to make it simpler is to limit
the data shared between threads to the absolute minimum.
The best model (IMHO) for background threads is message-passing. You
start the thread with some input data, it runs and returns some output
data that the main thread receives. If you need to give more data to
the thread while it's running, make the thread run a runloop and use
one of the threaded -performSelector calls to send it messages. (It
can likewise send data back to the main thread the same way.)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden