Re: Callbacks, GUI updates and threading
Re: Callbacks, GUI updates and threading
- Subject: Re: Callbacks, GUI updates and threading
- From: Hamish Allan <email@hidden>
- Date: Mon, 10 May 2004 16:51:39 +0100
On May 10, 2004, at 12:50, Andreas Mayer wrote:
You know, there's documentation out there ...
http://developer.apple.com/cgi-bin/search.pl?
&q=cocoa+thread&num=10&ie=utf8&oe=utf8&lr=lang_en&simp=1
http://developer.apple.com/cgi-bin/search.pl?
&q=performselectoronmainthread&num=10&ie=utf8&oe=utf8&lr=lang_en&simp=1
Yes, I've seen the stock method description from the NSObject class
docs.
(The other three of a mere five results from an ADC search are two
short code references which are fairly useless as an overview, and one
recommendation to use the method instead of distributed notifications,
which is even less use. And none of those results overlap with an ADC
search on "cocoa thread", which is really rather telling in itself. I
searched wider than ADC, too.)
I got just about enough information from that description to work out
what the method is for, but then I already knew that from your first
email. So I had a look at how to create threads and communicate between
them, etc., and it all seemed rather complicated considering that all I
wanted to do was run through the event loop (the operation itself is
effectively blocking from the user's point of view). I just didn't know
how I could do that from a single thread, but Brent very helpfully gave
me an overview and pointed me to the relevant API.
Your comment about ThreadWorker vs. performSelectorOnMainThread seemed
to suggest that the two were strict alternatives, which is not
necessarily the case. ThreadWorker still provides a mechanism to make
it easier to cancel threads, and to notify the parent thread of
completion. Admittedly as you say, cancellation is not hard to do with
a shared variable as there are no synchronisation problems, and in this
case the parent thread is the main thread, so
performSelectorOnMainThread can be used to notify completion. But I'm a
newbie, and it's hard to glean such information from such terse
comments as yours.
I'm still in two minds as to whether or not to use multithreading for
this. I think I probably will, as more and more people are likely to be
using multiprocessor machines as time goes on. But there is an
associated penalty, so it might be better to stick with the
single-threaded modal session approach. I might even write a helper
class to abstract the two approaches. If I do, I'll post a link to it
here!
Regards,
Hamish
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.