zoukankan      html  css  js  c++  java
  • GCD和NSOperationQueue添加依赖的方法

    - (void)dispatchGroup

    {

        dispatch_group_t group = dispatch_group_create();

        dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            NSLog(@"1--%@", [NSThread currentThread]);

        });

        dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            NSLog(@"2--%@", [NSThread currentThread]);

        });

        dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            NSLog(@"3---%@", [NSThread currentThread]);

        });

     

    }

     

    - (void)operation

    {

        NSOperationQueue *queue = [[NSOperationQueue alloc] init];

        NSOperation *operation1 = [NSBlockOperation blockOperationWithBlock:^{

            NSLog(@"1---%@", [NSThread currentThread]);

        }];

        NSOperation *operation2 = [NSBlockOperation blockOperationWithBlock:^{

            NSLog(@"2---%@", [NSThread currentThread]);

        }];

        NSOperation *operation3 = [NSBlockOperation blockOperationWithBlock:^{

            NSLog(@"3---%@", [NSThread currentThread]);

        }];

        [operation1 addDependency:operation2];

        [operation2 addDependency:operation3];

        

        [queue addOperation:operation1];

        [queue addOperation:operation2];

        [queue addOperation:operation3];

    }

  • 相关阅读:
    Java自定义注解(1)
    SpringMvc入门
    Nginx服务器简单配置
    EL和JSTL使用笔记
    JQuery笔记
    Java05 JDBC介绍及基本操作
    Java04 线程同步问题解决——线程锁(同步锁、互斥锁)
    web服务、正向代理、反向代理的一点理解
    java03 IO操作
    Docker05 Docker容器
  • 原文地址:https://www.cnblogs.com/bing-ge/p/4606095.html
Copyright © 2011-2022 走看看