Re: Multithreading and NSNotifications
Re: Multithreading and NSNotifications
- Subject: Re: Multithreading and NSNotifications
- From: Anthony Byrne <email@hidden>
- Date: Tue, 22 Nov 2005 12:17:13 -0500
On Nov 21, 2005, at 7:36 PM, email@hidden wrote:
Later on, object A decides it is time to have object B do something
in a different thread, so I use NSThread's
detachNewThreadSelector: ... message. However, I want this process
that object B is working on to be cancelable at a particular point
without much overhead, so I thought I would have object A post an
NSNotification. Optimally, object B would have an opportunity to
respond to that NSNotification at some point in the thread's
execution, but how would I go about doing this?
Hi Andrew,
Here's one way you could do it. Object A sends a notification to
object B. Note that object B will receive this notification on
object A's thread (likely your main thread). Meanwhile it's worker
thread is occupied elsewhere. Object B's notification handler could
set a condition on an NSConditionLock that indicates the worker
thread should abort. However it will be up to the worker thread to
check this condition periodically. If it's iterating through a loop
(as worker threads often are), it shouldn't be too hard. Otherwise
you'll have to figure out where the logical places for it to quit
might be.
Good luck,
Tony Byrne
_______________________________________________
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