zoukankan      html  css  js  c++  java
  • GCD的简单封装

     扩展: dispatch_block_t :无参数block,使用起来很简单

     下载链接:http://pan.baidu.com/s/1bndN6Yb

       //串行队列
    - (void)test1 {
      
        WJGCDQueue *queue = [[WJGCDQueue alloc]initSerial];
        [queue execute:^{
            NSLog(@"1--%@",[NSThread currentThread]);
        }];
        [queue execute:^{
            NSLog(@"2--%@",[NSThread currentThread]);
        }];
        [queue execute:^{
            NSLog(@"3--%@",[NSThread currentThread]);
        }];
    }
        //并行队列
    - (void)test2 {
        
        WJGCDQueue *queue = [[WJGCDQueue alloc]initConcurrent];
        [queue execute:^{
            NSLog(@"1--%@",[NSThread currentThread]);
        }];
        [queue execute:^{
            NSLog(@"2--%@",[NSThread currentThread]);
        }];
        [queue execute:^{
            NSLog(@"3--%@",[NSThread currentThread]);
        }];
    }

       //复杂运算,更新ui
    - (void)test3 {
        
        [WJGCDQueue executeInGlobalQueue:^{
            NSLog(@"处理业务逻辑");
            [WJGCDQueue executeInMainQueue:^{
                NSLog(@"更新UI");
            }];
        }];
    }
        //延时操作
    - (void)test4 {
        NSLog(@"%@",[NSDate date]);
        [WJGCDQueue executeInMainQueue:^{
             NSLog(@"%@",[NSDate date]);
        } afterDelaySecs:2];
    }
        //定时器
    - (void)test5 {
        self.gcdTimer = [[WJGCDTimer alloc]initInQueue:[WJGCDQueue mainQueue]];
        [self.gcdTimer event:^{
            NSLog(@"GCD定时器");
        } timeInterval:NSEC_PER_SEC];
        [self.gcdTimer start];
    }
        //队列组
    - (void)test6 {
        WJGCDGroup *group = [[WJGCDGroup alloc]init];
        WJGCDQueue *queue = [[WJGCDQueue alloc]initConcurrent];
        [queue execute:^{
            NSLog(@"线程1");
        } inGroup:group];
        [queue notify:^{
            NSLog(@"线程执行");
        } inGroup:group];
    }

        //信号量
    - (void)test7 {
        WJGCDSemaphore *semaphore = [[WJGCDSemaphore alloc]init];
        [semaphore signal];
        [semaphore wait];
    }
  • 相关阅读:
    MSSQL安全审计文件执行Rootkit-WarSQLKit
    组建自己的局域网服务器
    python openpyxl表格样式设置
    ssh 和 scp 命令访问非默认22端口。
    set | grep IFS
    Python: check if key exists in dictionary (6 Ways)
    在线Jinja2解析器
    FastApi教程|测试WebSockets
    QT Qstring的用法
    QT UI拖拽方法
  • 原文地址:https://www.cnblogs.com/hxwj/p/4669163.html
Copyright © 2011-2022 走看看