为什么需要为每个线程创建ABAddressbookRef? [英] Why would ABAddressbookRef need to be created for each thread?

查看:122
本文介绍了为什么需要为每个线程创建ABAddressbookRef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple说:


重要:多个
线程不能使用ABAddressBookRef的实例。每个线程必须创建自己的实例。

Important: Instances of ABAddressBookRef can not be used by multiple threads. Each thread must make its own instance.

但为什么?

I知道必须在主线程中完成一些特定的类或操作。

I know that some particular class or operations must be done in main thread.

我知道有些对象不是线程安全的(这意味着如果这些对象是同时由两个不同的线程访问)。

And I know some objects are not thread-safe (which means it would cause problem if these objects are accessed by two different threads concurrently).

但是,如果你可以确保任何时刻只有一个线程访问线程不安全的对象,那么应该没问题。

But, if you can make sure that the the thread-unsafe objects are accessed by only one thread at any moment, then there should be no problem.

到目前为止,我是否理解正确?

Do I understand correctly thus far?

我无法理解的是,为什么是否需要为每个线程创建一些像ABAddressbookRef这样的对象?为什么苹果会说这样的话?如果只是它的线程不安全,Apple可以说它的线程不安全,在处理它时要小心。但为什么需要为每个线程创建一个?我有什么理由不知道吗?

What I can't understand is, Why would some objects like ABAddressbookRef need to be created for each thread? Why would Apple say something like this? If it's just that it's thread-unsafe, Apple can says it's thread-unsafe, be careful when handling it. But why is there a need to create one for each thread? Is there any reason that I don't know?

ABAddressbookRef的实现是否依赖于创建它的线程?

Does the implementation of ABAddressbookRef rely on the thread which created it?

PS:我记得Core Data还说需要为每个使用它的线程创建ManagedObjectContext。

PS: I remember that Core Data also says ManagedObjectContext need to be creates for each thread which uses it.

推荐答案

为了结束推测,我使用付费支持向Apple询问有关ABAddressBookRef和多线程的明确答案。

To put an end to the speculation I used paid support to ask Apple for a definite answer regarding ABAddressBookRef and multiple threads.

以下是我的问题:


对此事进行了大量猜测,我决定要求一位了解实施细节的工程师给出明确答复ABAddressBook Framework。

There has been a lot of speculation on the matter and I decided I would like to ask for a definite answer from an engineer who is well aware of the implementation details of ABAddressBook Framework.

文档说明:
多个线程不能使用ABAddressBookRef的重要实例。每个线程必须创建自己的实例。

The documentation states: Important Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance.

如果我按字面意思理解,这意味着即使使用GCD串行队列也必须在每个块中创建ABAddressBookRef,因为GCD不提供任何保证全局主线程旁边的线程。

If I take this literally, it means that ABAddressBookRef must be created in each block even with GCD serial queues since GCD does not give any guarantees about threads beside the global main thread.

我想问一下这是不是它的意思,或者,是否足以确保没有两个线程同时访问同一个ABAddressBookRef GCD专用串行队列保证的时刻。

I want to ask if this is literally how it is meant, OR, is it enough to ensure that no two threads are accessing the same ABAddressBookRef at the same time at any moment which GCD private serial queue does guarantee.

以下是我从Apple获得的回报。

And here is what I got in return from Apple.


感谢您联系Apple Worldwide Developer技术支持。我的回复是告诉您我已收到您的技术协助请求。

这是正确的。这是因为地址簿对象永远不应跨越线程边界。 因此,每个块必须有自己的实例。

这是个坏消息。

这篇关于为什么需要为每个线程创建ABAddressbookRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆