Re: NSTask, or threading?
Re: NSTask, or threading?
- Subject: Re: NSTask, or threading?
- From: Richard Frith-Macdonald <email@hidden>
- Date: Sun, 26 Apr 2009 20:29:10 +0100
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