In apple's document, apple says:
Important: Instances of ABAddressBookRef can not be used by multiple threads. Each thread must make its own instance.
And
Record objects can not be passed across threads safely.Instead,you should pass the corresponding record identifier
What does the first one mean?If i can assure that every moment there is only one thread that is accessing the ABAddressBookRef, can I use this ABAddressBookRef in multiple threads?
And the second one,what does can not be passed across threads safely really mean?
And seems that GCD do not assure all the blocks are excuted in the same thread even the blocks are in a same serial queue.
So does this mean that I can't use GCD to deal wi开发者_开发百科th the ABAddressBook framework? Or I can only create a ABAddressBookRef in each block?(I've tested this, really slow)
This question covers the same issue. It's not that ABAddressBook isn't thread-safe, it means you can't use multi-threading at all.
However you could write a wrapper class with getter / setter methods to do what you need, which could be called from arbitrary threads inside a dispatch block. All the 'mutating' functions inside the wrapper will all have to happen on the same thread though. Maybe consider looking at the dispatch_once documentation for using grand-central to protect against multiple instantiation.
精彩评论