Re: Threads, messages and blocking
Re: Threads, messages and blocking
- Subject: Re: Threads, messages and blocking
- From: Drew McCormack <email@hidden>
- Date: Fri, 30 May 2003 12:13:18 +0200
Yes, thread 1 is the main application thread.
performSelectorOnMainThread
looks like it could help. But I'm not sure it will completely solve
the
problem. Sometimes I'll have thread 2 idle while thread 1 does
unrelated
stuff, and then thread 1 will need it to do something.
performSelectorOnMainThread only allows communication thread
2->thread 1
(main thread), it appears. So it doesn't give me any way to have the
main
thread send thread 2 another "go to work" message. Am I
misunderstanding the
suggestion?
The way it is often done is that a second thread is split off with the
"detachThread..." method, and that this is the "go to work" method.
You split off a new thread each time you have some work, and it calls
back with the performSelectorOnMainThread when it is finished.
I guess having a different thread for each piece of work could be
expensive if your units of work are short, but if they are so short,
you probably don't need multithreading.
Sorry to answer my own post, but I just realized that this was a good
opportunity to plug my latest article:
http://www.macdevcenter.com/pub/a/mac/2003/05/23/multiprocessor.html
It is about multithreading, with multiprocessor systems in mind, but it
works just as well on a single processor. It is designed to perform
many independent tasks, but if you only have one task, it works fine
too.
It uses delegate methods as callbacks to indicate to the main thread
when it is finished, amongst other things.
In any case, the source code available should show you how to split of
a thread, and call back.
Drew
----------------------------------
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Stock Market strategy design platform for Mac OS X.
_______________________________________________
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.