Re: Recurrent background thread
Re: Recurrent background thread
- Subject: Re: Recurrent background thread
- From: Jens Alfke <email@hidden>
- Date: Fri, 13 May 2016 13:56:22 -0700
> On May 13, 2016, at 12:34 PM, Carl Hoefs <email@hidden> wrote:
>
> As a test, the above works if run on the main thread, so I'm guessing it has something to do with there being no runloop after the background thread exits.
Yup. More precisely, the background thread has no runloop at all. Its top-level function is the method you’re running, so as soon as your method returns, the thread exits.
You can use runloops on background threads, but the thread’s top-level function has to end with
[[NSRunLoop currentRunLoop] run];
which starts the runloop. That call generally never returns, unless you stop that runloop.
These days it’s probably better to use dispatch queues instead.
—Jens
_______________________________________________
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