dispatch_set_target_queue这个函数想找具体的代码来实现一下,找了半天没找到怎么来试验它,在51CTO上找了篇博文,看着还不错。
All user queues have a target queue concept. Essentially, a user queue does not actually perform any tasks, but it passes the task to its target queue for execution. Typically, the destination queue is the default priority of the global queue.
The target queue of the user queue can be modified with a function dispatch_set_target_queue
. We can pass any dispatch queue to this function, or even another user queue, as long as you don't make a loop. This function can be used to set the priority of the user queue. For example, if we can set the target queue of the user queue to a low priority global queue, then the tasks in our user queue will be executed at a low priority level. High priority is the same thing.
One use is to set the target of the user queue as the main queue. This causes all blocks submitted to the user queue to be executed in the main thread. The advantage of doing this instead of executing code directly in the main thread is that our user queue can be suspended and restored individually, and the target can be reset to a global queue, and then all blocks become executed on the global queue (as long as you ensure that your code leaves the main thread without problems).
Another use is to designate the target queue for one user queue as a second user queue. This forces multiple queues to be executed serially in a coordinated manner, which is enough to build a set of queues that we can suspend and pause the entire group by suspending and pausing that target queue. Imagine a program that scans a set of directories and loads the contents of a directory. To avoid disk contention, we want to make sure that only one file load task is executing on the same physical disk. Instead, you want to be able to read multiple files from different physical disks at the same time. To achieve this, all we have to do is create a dispatch queue structure that mirrors the disk structure.
First, we scan the system and find each disk, creating a user queue for each disk. Then scan the file system and create a user queue for each file system to point the target queue of those user queues to the appropriate disk user queue. Finally, each directory scanner has its own queue, and its destination queue points to the queue of the file system where the directory resides. The directory scanner enumerates its own directories and submits a block to its own queue for each file. Because of the way the whole system is built, each physical disk is accessed serially, and multiple physical disks are accessed in parallel. In addition to the queue initialization process, we do not need to manually intervene in anything at all.
Reference: http://mobile.51cto.com/hot-403005.htm
Target designation of GCD