Re: NSThread subclass get blocked on 'start' method call
Re: NSThread subclass get blocked on 'start' method call
- Subject: Re: NSThread subclass get blocked on 'start' method call
- From: John Daniel <email@hidden>
- Date: Mon, 28 Sep 2015 15:12:29 -0400
> On Sep 28, 2015, at 3:00 PM, email@hidden wrote:
>
> I have problem with NSThread subclass. It's very similar to this case - http://prod.lists.apple.com/archives/cocoa-dev/2015/Sep/msg00454.html <http://prod.lists.apple.com/archives/cocoa-dev/2015/Sep/msg00454.html>.
> I have a library, that provide developer-friendly interface to AddressBook.framework. And I unable to use GCD for thread safety, because of `ABAddressBookRegisterExternalChangeCallback` function, that requires a run loop to schedule callback.
> So I decided to use NSThread subclass. And found that second NSThread instance blocks main thread on `start` method call.
> Here is the source code of Example - https://www.dropbox.com/s/r5k8o28pocu7afk/aptest.zip?dl=0 <https://www.dropbox.com/s/r5k8o28pocu7afk/aptest.zip?dl=0>
> When you press 'load contacts' for the second time, it'll block main thread with `semaphore_wait_trap`
> Any ideas?
Why are you using threads at all? If there is a run loop callback, that probably means you should schedule it on the run loop. Don’t introduce threading unless you are doing something in that callback that blocks the UI. Even then, schedule your callback on the UI run loop and have your callback spawn the thread or async block.
And that API is deprecated in iOS9 anyway. If you don’t need to support iOS 8 or earlier, use the new Contacts API.
John Daniel
_______________________________________________
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