How does dispatch_set_target_queue work?

前端 未结 1 1745
青春惊慌失措
青春惊慌失措 2021-01-12 17:08

Due to the lack of material on dispatch_set_target_queue, I have come here for help, so thanks!

Here is my test code:

dispatch_queue_t          


        
相关标签:
1条回答
  • 2021-01-12 17:28

    According to me when you set a target queue to other you are synchronizing the task of both the queue so
    In first case:

    dispatch_set_target_queue(mySerialDispatchQueue2, mySerialDispatchQueue1);
    

    mySerialDispatchQueue1 is target queue so all the task added in mySerialDispatchQueue2 is also enqueued from the mySerialDispatchQueue1. As it is target queue.So mySerialDispatchQueue1 has already two task so other one from queue mySerialDispatchQueue2 is added later.

    In second Case:

    dispatch_set_target_queue(mySerialDispatchQueue1, mySerialDispatchQueue2);
    

    your target queue is mySerialDispatchQueue2 so in start when there is no task then task from mySerialDispatchQueue1 is added in the mySerialDispatchQueue2 then its own task is in queue. So in this way task has been added.

    0 讨论(0)
提交回复
热议问题