Re: Threads
Re: Threads
- Subject: Re: Threads
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 11 Jul 2016 16:18:30 +0700
> On 11 Jul 2016, at 16:00, Alastair Houghton <email@hidden> wrote:
>
> On 11 Jul 2016, at 06:35, Gerriet M. Denkmann <email@hidden> wrote:
>>
>> I have a subclass of NSThread (called MyThread), which runs a RunLoop in main.
>> When it gets cancelled, it leaves the RunLoop and main will exit.
>
> One further thought on this: it looks like you might be duplicating the functionality of NSOperationQueue and/or GCD, in which case you might consider using those instead?
Yes. I liked the idea of GCD better than NSLocks.
I created a serial queue for MyThread called serialQueue.
Then I overrode cancel in MyThread:
- (void)cancel
{
dispatch_async( self.serialQueue, ^void{ [ super cancel ] } );
}
And added to MyThread:
- (void)performSelector: (SEL)aSelector withObject: object;
{
dispatch_async( self.serialQueue, ^void
{
if ( self.isCancelled ) return;
[ self performSelector: aSelector
onThread: self
withObject: object
waitUntilDone: NO
];
}
);
}
I think this solves my problem.
Thanks a lot for your help!
Kind regards,
Gerriet.
_______________________________________________
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
References: | |
| >Threads (From: "Gerriet M. Denkmann" <email@hidden>) |
| >Re: Threads (From: Alastair Houghton <email@hidden>) |