• dispatch_queue


    dispatch_group_notify方法调用执行时,如果没有添加到group的任务在执行,那么直接执行notify的Block,如果有则等待现有的任务执行完之后执行notify的Block

    - (void)test_1 {
        dispatch_group_t group = dispatch_group_create();
        dispatch_queue_t queue = dispatch_queue_create("test_for_group_events", DISPATCH_QUEUE_CONCURRENT);
        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            NSLog(@"=========> finsh running 00");
        });
        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            NSLog(@"=========> finsh running 01");
        });
        dispatch_group_async(group, queue, ^{
            [NSThread sleepForTimeInterval:1.0];
            NSLog(@"============> 1");
        });
        dispatch_group_enter(group);
        dispatch_async(queue, ^{
            [NSThread sleepForTimeInterval:0.6];
            NSLog(@"============> 2");
            dispatch_group_leave(group);
        });
        dispatch_group_notify(group, queue, ^{
            NSLog(@"=========> finsh running 02");
        });
        dispatch_group_enter(group);
        dispatch_async(dispatch_get_main_queue(), ^{
            [NSThread sleepForTimeInterval:0.3];
            NSLog(@"============> 3");
            dispatch_group_leave(group);
        });
        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            NSLog(@"=========> finsh running 03");
        });
        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            NSLog(@"=========> finsh running 04");
        });
    }

    给dispatch_queue增加属性

    dispatch_queue_set_specific(_queue, kDispatchQueueSpecificKey, (__bridge void *)self, NULL);

    dispatch_sync(dispatch_get_global_queue(0, 0), ^{
            NSLog(@"是否在主线程执行:%d",[NSThread isMainThread]);
            NSLog(@"%@",[NSOperationQueue currentQueue]);
        });

    在主线程调用同步,输出为是主线程、为主队列

  • 相关阅读:
    js外观模式
    微服务架构的基础框架选择:Spring Cloud还是Dubbo?
    JAVA 中BIO,NIO,AIO的理解
    Reactor和Proactor模式的讲解(关于异步,同步,阻塞与非阻塞)
    JVM(Java虚拟机)优化大全和案例实战
    php编译安装后,加扩展模块
    mysql查所有列名
    cannot get uid for user 'www'
    rabbitmq management Login Failed
    nginx 安装过程中的not found
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/12895721.html
Copyright © 2020-2023  润新知