Re: some NSThread questions
Re: some NSThread questions
- Subject: Re: some NSThread questions
- From: "Louis C. Sacha" <email@hidden>
- Date: Tue, 1 Jun 2004 20:16:19 -0700
Hello...
The most likely reason why the application is locking up is that this
code is being executed on the main thread, since it appears to be the
action for the stop button. Therefore sending the [NSThread exit]
message is causing the main thread (the current thread) to exit and
not the detached thread you created to do your calculation.
As Dustin mentioned, the simplest solution is to modify the code you
are using in the thread to check for a flag when possible during the
processing to see if the thread should exit (since the [NSThread
exit] message must be sent when the detached thread is the current
thread). This could be as often as every time through a particular
loop, or in your case maybe as a check between each calculation in
the sequence.
Other possibilities (although not necessarily good ones) include:
1) just turning off the output to the text view that is coming from
that particular thread and just let the detached thread run until it
finishes in the background.
2) running the code that is used in the detached thread as a tool
instead, using NSTask, since as a seperate process the task is easier
to control from outside code.
The second option (using a separate task) is significantly better
than the first (turning off the output), but it might not be very
efficient if you are dealing with large amounts of data that are
already loaded into your application's memory.
Hope that helps,
Louis
...
Also, when I use the stop button, the thread apparently stops (I get
no more output from the calculation), but the stop button remains
blue, and after a while I get a spinning beachball. It could well be
related to somthing in the calculation, but just to be sure, this is
what I use to stop the thread:
-(IBAction)stop:(id)sender
{
[NSThread exit];
// myPrintf("Calculation was interrupted by the user");
}
...
thanks,
- Koen.
_______________________________________________
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.