• dispatch_set_target_queue测试


    dispatch_set_target_queue会将其他queue转为和targetqueue一样的优先级和执行时序,看下面的例子

    即使queue1,queue2,queue3,都是并行的queue,但是输出结果仍然是串行的结果;

    - (void)testTargetQueue
    {
        dispatch_queue_t targetQueue = dispatch_queue_create("test.target.queue", DISPATCH_QUEUE_SERIAL);
        dispatch_queue_t queue1 = dispatch_queue_create("test.1", DISPATCH_QUEUE_CONCURRENT);
        dispatch_queue_t queue2 = dispatch_queue_create("test.2", DISPATCH_QUEUE_CONCURRENT);
        dispatch_queue_t queue3 = dispatch_queue_create("test.3", DISPATCH_QUEUE_CONCURRENT);
        dispatch_set_target_queue(queue1, targetQueue);
        dispatch_set_target_queue(queue2, targetQueue);
        dispatch_set_target_queue(queue3, targetQueue);
        
        dispatch_async(queue1, ^{
            NSLog(@"1 in");
            [NSThread sleepForTimeInterval:3.f];
            NSLog(@"1 out");
        });
        
        dispatch_async(queue2, ^{
            NSLog(@"2 in");
            [NSThread sleepForTimeInterval:2.f];
            NSLog(@"2 out");
        });
        dispatch_async(queue3, ^{
            NSLog(@"3 in");
            [NSThread sleepForTimeInterval:1.f];
            NSLog(@"3 out");
        });
    }
    

      

    2017-03-07 20:31:11.636 DispatchTargetQueueTest[42985:377250] 1 in

    2017-03-07 20:31:14.711 DispatchTargetQueueTest[42985:377250] 1 out

    2017-03-07 20:31:14.711 DispatchTargetQueueTest[42985:377250] 2 in

    2017-03-07 20:31:16.784 DispatchTargetQueueTest[42985:377250] 2 out

    2017-03-07 20:31:16.784 DispatchTargetQueueTest[42985:377250] 3 in

    2017-03-07 20:31:17.859 DispatchTargetQueueTest[42985:377250] 3 out

  • 相关阅读:
    cesium学习——cesium中的坐标
    webService框架CXF的简单使用
    使用cesium中的scene.open中遇到的几个问题
    通过Spring读取properties配置文件
    常用的Ant风格书写
    oracle小知识点
    虚拟机centos7系统下安装hadoop ha和yarn ha(详细)
    java 注解
    Guava Immutable 不可变集合
    Guava BiMap
  • 原文地址:https://www.cnblogs.com/wxm5558/p/6516675.html
Copyright © 2020-2023  润新知