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: Morphine <email@hidden>
- Date: Wed, 19 May 2004 10:22:33 +0200
Sorry but I didn't express myself properly. My explanation was not
clear.
Yes I use Distributed Objects to communicate between threads. You are
right (I tested it) if I call "pleaseStop" I can stop the loop. But I
can call directly the method because sometimes the thread is not a
thread but an application :-(
After the night I had an idea, I call runLoop a short delay after each
iteration :
- (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...
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.0000001]];
}
}
- (void oneway) pleaseStop { // this method is called by the main
application
stop = YES ;
}
But I've a new question now... I've choose to set a date very short.
I've a 2xG4 processor. What's happens on a slower computer ???
Thank you very much.
Le 19 mai 04, ` 00:38, Dave Camp a icrit :
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.
______________________________________
_______________________________________________
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.