Re: stop a lengthy task in a thread
Re: stop a lengthy task in a thread
- Subject: Re: stop a lengthy task in a thread
- From: Dave Camp <email@hidden>
- Date: Tue, 18 May 2004 15:38:18 -0700
On May 18, 2004, at 2:32 PM, Morphine wrote:
Hello,
I don't found how to stop a lengthy task in a thread !!!
Here, what I have do :
IN THE THREAD :
- (void oneway) calcul { // this method is called by the main
application
NSDirectoryEnumerator *enumDirectories = [fileManager
enumeratorAtPath:@"/"] ;
while (file = [enumDirectories nextObject]) {
if (stop) break ; // stop is declared in header file as BOOL
// a task...
}
}
- (void oneway) pleaseStop { // this method is called by the main
application
NSLock *lock = [[NSLock alloc] init] ;
[lock lock] ;
stop = YES ;
[lock unlock] ;
}
How to do for set the "stop" bool to change it's state ???
You don't mention it, but your code suggests you are using Distributed
Objects to communicate between threads. Based on that, I'm going to
guess the call to pleaseStop is scheduled on the runloop for calcul()
but is never run because calcul() is in a tight loop and not processing
mach messages.
You either need to make the call to pleaseStop not use DO (i.e. execute
on the caller's thread, or somehow make it execute on a different
thread than calcul().
Dave
---
In English, every word can be verbed.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.