Re: NSTask, or threading?
Re: NSTask, or threading?
- Subject: Re: NSTask, or threading?
- From: James Maxwell <email@hidden>
- Date: Sun, 26 Apr 2009 15:35:20 -0700
Thanks for this. I actually found your page while googling around for
help. I'll check it out now.
Cheers,
J.
Sent from my iPod
On 26-Apr-09, at 12:29 PM, Richard Frith-Macdonald <email@hidden
> wrote:
On 26 Apr 2009, at 18:39, James Maxwell wrote:
So, how can I put my dataThing into some process, thread, etc., in
a way that keeps it totally in its "own world", so to speak?
There is a simple an easy way to keep it in a separate thread ... so
that's probably what you want to do.
You would use 'Distributed Objects' (the NSConnection class) to
communicate between the main thread and the dataThing thread.
The way it works is as follows:
1. your code creates a pair of NSPort objects to talk to each other.
2. it launches a second thread, and in that thread creates a server
NSConnection using those ports, and registers your dataThing object
as the server object for the NSConnection
3. in the main thread another (client) NSConnection is created using
the same two ports, and you ask the client connection for its 'root
object'
From then on, the main thread sends messages to the 'root object' of
the connection exactly as if it was sending them directly to the
dataThing object, and the NSConnection code manages things for you
so you don't have to worry about locking.
There's an example of this sort of thing at http://lachand.free.fr/cocoa/Threads.html
_______________________________________________
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