Re: NSTask, or threading?
Re: NSTask, or threading?
- Subject: Re: NSTask, or threading?
- From: Richard Frith-Macdonald <email@hidden>
- Date: Tue, 28 Apr 2009 08:18:46 +0100
On 27 Apr 2009, at 20:22, James Maxwell wrote:
ugh... Okay, so I got rid of all the shared instances (of my own
classes, that is) but I'm still getting stuttering. Is there
anything in the settings of the thread itself that I should check?
Or is there some other newbie "gotcha" that I should be aware of?
thanks in advance for any thoughts...
J.
Well, perhaps the main thread could be blocking, waiting for the other
thread to respond to a message?
If you send a message to your dataThing object from your main thread,
the main thread will wait for a response, and will not necessarily
deal with all the events you want while waiting for the response.
As long as your dataThing API methods return void, you can avoid this
problem by declaring the methods as 'oneway' ... which tells the
distributed objects system that it can call the method asynchronously
(so the main thread does not need to wait for a response).
Essentially the model needs to be that the main thread sends data to
the dataThing thread using an asynchronous (oneway void) method, and
the second thread then does computation, comes up with a result, and
sends that result back to the main thread using another asynchronous
method. That way, neither thread needs to wait for the other.
A big advantage of using NSConnection is that you an easily split your
application into multiple processes (possibly running on multiple
machines) rather than just multiple threads.
However, if you don't need that option, and if you are targeting only
the latest MacOS-X API, there is another approach you can take, using
the -performSelector:onThread:withObject:waitUntilDone:modes: method
of NSObject to send messages to a dataThing object in a second thread
from the main thread. Using this new method is more efficient, but
less flexible than using NSConnection.
_______________________________________________
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