Re: Exiting non-POSIX threads?
Re: Exiting non-POSIX threads?
- Subject: Re: Exiting non-POSIX threads?
- From: Richard Somers <email@hidden>
- Date: Thu, 01 Aug 2013 08:55:59 -0600
On Jul 29, 2013, at 2:34 AM, Oleg Krupnov <email@hidden> wrote:
> Is there a way to exit a GCD thread?
You can exit a GCD thread with something like this.
- (void)invalidateQueue
{
_isQueueCanceled = YES;
dispatch_sync(_queue, ^{});
}
- (void)submitWorkToBeDone
{
dispatch_async(_queue, ^{
for ( ... ) {
if (_isQueueCanceled == YES) {
break;
} else {
// do work
}
}
});
}
When invalidateQueue returns the thread has been canceled.
Richard Somers
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden