Re: NSThread close (exit)
Re: NSThread close (exit)
- Subject: Re: NSThread close (exit)
- From: Paul Forgey <email@hidden>
- Date: Wed, 5 Apr 2006 19:40:14 -0700
You can communicate with your threads just like any remote process
over a mach port. If you've never had to deal with writing and
rewriting code for inter-thread communication then you'd probably not
appreciate just how cool this is (or for that matter distributed
objects after dealing with RPC or COM style schemes). So one method
you could use to cleanly exit a thread is to send it a message asking
it to quit, similar to how you were initially thinking it would work.
This isn't a route to take if the purpose of your thread is to go off
and do something where it will never go through it's message queue.
Otherwise if your thread is there to periodically wake up and do
short amounts of work when asked, this is a neat-o way to go about it.
Refer to Apple's documentation under
Cocoa/Process Management/Multithreaded Programming Topics
and
Cocoa/Interapplication Communication/Distributed Objects
In the first topic, especially read "Communicating With Distributed
Objects".
Whatever you do, make sure there's only one way for the thread
process to quit. Either under it's own power or externally, but
never both.
On Apr 5, 2006, at 5:03 AM, Christian Stieber wrote:
At 14:00 05.04.2006 +0200, Yorh wrote:
-(void)stopThread{
[NSThread exit];
}
Of course if I exit from the thread in this way the stopped thread is
the main one... How can I select a specific thread?
You can't. What you do is to define some form of telling
the thread to quit within your protocol that tells the
thread what to do. For example, if you have a simple
producer/consumer relation, with the main thread sticking
work packets into the queue and then waking up the child thread
(traditionally this would be implemtned with a Condition lock),
you could just define a BOOL ThreadQuit and have the child
check that after it obtains the lock. Or, in the same case, if you
want a "cleaner" exit you could declare that an NSNull instance
in the work queue is the signal for the thread to quit.
Christian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden