Re: Pausing and terminating a thread
Re: Pausing and terminating a thread
- Subject: Re: Pausing and terminating a thread
- From: Ben Haller <email@hidden>
- Date: Tue, 30 Aug 2005 15:18:55 -0700
On Aug 30, 2005, at 10:16 AM, Hamish Allan wrote:
On Mon, 29 Aug 2005 23:23:08 -0700, Steve Weller
<email@hidden> wrote:
So I can use a lock to implement the pause -- neat...
However this still requires that my worker thread poll. And doesn't
take care of quitting the worker thread. Any better way?
It's not clear what you would like to be able to do. Do you mean
you want to be able to pause and terminate your worker thread
without performing any tests within its main loop?
Is there not communication between worker and GUI anyway, to inform
of progress?
I've run into the same question. You want a background thread to
do a whole lot of work as fast as possible. Due to user actions or
whatever, though, you may want to pause or terminate the background
thread at some unpredictable time in the future. As far as I was
able to figure out, the background thread must poll to determine if
it is supposed to pause or terminate.
And as an aside: you might think this would be fairly irrelevant;
how long does it take to check a flag every 1/10th of a second, for
example? But the problem is the logic that figures out "I've been
working long enough that it's time to check my flag". That logic
would have to run every time though the loop of whatever your thread
is doing, of course, which is a silly waste of time; so you end up
having to just check the flag every time through your loop, as that
is faster than trying to figure out if it's time to check your flag
yet. If your work loop is doing easy, fast stuff, you end up
checking the flag a *lot*, and it slows down your work
significantly. Unrolling your work loop can help somewhat, but of
course you don't want to do that too much or you'll start causing
cache problems because your code is too big, plus of course unrolled
code is hard to maintain. So it's an annoying problem.
It would sure be nice to have a way of pausing and killing
background threads from the main thread without polling, is what I'm
saying. :->
Ben Haller
Stick Software
_______________________________________________
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