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 21:38:55 -0700
On Aug 30, 2005, at 6:30 PM, Pandaa wrote:
31 aug 2005 kl. 02.48 skrev Ben Haller:
Right; if I understand your code correctly, though, you are
polling the "stopThread" ivar every time through your loop. If
your loop took very little time to complete one iteration, that
polling would end up taking a substantial amount of the total time
taken by the thread. The only solution to that (as far as anybody
on the list so far seems to know) is unrolling the loop so that
you only have to check the flag every x iterations. That's the
problem....
Is there any reason you can't use a pthread with cancel type
PTHREAD_CANCEL_ASYNCHRONOUS and pthread_cleanup_push / pop ?
See, e.g. "Thread Cancellation And Termination" in http://
users.actcom.co.il/~choo/lupg/tutorials/multi-thread/multi-
thread.html and the man page for pthread_cleanup_push.
Hmm, interesting. Are NSThreads guaranteed to be POSIX threads
under the hood, or do they just happen to be at present? In any case,
it seems they are certainly distinct in some ways. Which I guess is
exactly what we're talking about here.
I'd be nervous about doing things to NSThreads (like terminating
them) behind Cocoa's back; unless Apple has guaranteed that this is
OK, I'd worry that it would only work on some OS releases, and might
have weird side effects. Has anybody tried it?
You could certainly just use pthreads all the way through, but
then you'd lose various NSThread niceties, and I wonder if there are
ways in which AppKit or Foundation might not like being called from a
background thread that was not an NSThread.
And I only just glanced at the references you gave, just long
enough to see they were about pthreads, not Cocoa threads, so sorry
if I completely missed the point here.
In any case, the limits of my knowledge have been reached, so I
don't imagine I'll be posting on this topic again; I'd love to hear
more if anybody has played around with pthreads and Cocoa, though...
or if Chris Kane would like to weigh in, of course :->...
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