Does GCD assure that all the blocks working in the same queue are always working in a same thread?
If I create a dispatch queue and dispath_async blocks to this queue, does all the blocks that dispatch to that queue works in the same thread?
Since I’m working on a project that uses ABAdrressbook Framerowk and the document says that ABAddressBookRef and ABRecordRef can’t be used between threads, so I wonder if all the blocks in the queue are in the same thread, I can create only one AddressBookRef for that queue.
The only queue bound to a specific thread is the main queue, which is bound to the main (UI) thread.
If the only requirement is not to concurrently access the object, using a serial queue should work fine.
If the object instead relies on thread-local state, you will have to force all manipulation to a specific thread. The easiest would be to target your serial queue to the main thread, but that only works if you know you’re not going to be stuck for long in the block; otherwise, you will hang your UI. In that case, you’ll have to create your own handler thread and send the work over there.