zoukankan      html  css  js  c++  java
  • 线程、同步异步、队列

     1  dispatch_queue_t _serialQueue = dispatch_queue_create("gao mao a", DISPATCH_QUEUE_SERIAL);
     2     //(两个队列,都是同步的时候,就没什么卵用了,一个队列就够了)
     3     dispatch_queue_t _gaomaoa  = dispatch_queue_create("gao maoss a", DISPATCH_QUEUE_SERIAL);
     4     
     5     NSLog(@"wo ca lei ge da ye =======  1  
    ");
     6     //同步
     7     dispatch_async(_gaomaoa, ^{
     8         NSLog(@"wo ca lei ge da ye =======  2  
    ");
     9         NSLog(@"wo ca lei ge da ye =======  2  
    ");
    10         NSLog(@"wo ca lei ge da ye =======  2  
    ");
    11         NSLog(@"wo ca lei ge da ye =======  2  
    ");
    12         NSLog(@"wo ca lei ge da ye =======  2  
    ");
    13     });
    14     //异步
    15     dispatch_sync(_serialQueue, ^{
    16         NSLog(@"wo ca lei ge da ye =======  3  
    ");
    17         NSLog(@"wo ca lei ge da ye =======  3  
    ");
    18         NSLog(@"wo ca lei ge da ye =======  3  
    ");
    19         NSLog(@"wo ca lei ge da ye =======  3  
    ");
    20         NSLog(@"wo ca lei ge da ye =======  3  
    ");
    21     });
    22     
    23     dispatch_sync(_serialQueue, ^{
    24         NSLog(@"wo ca lei ge da ye =======  4  
    ");
    25         NSLog(@"wo ca lei ge da ye =======  4  
    ");
    26         NSLog(@"wo ca lei ge da ye =======  4  
    ");
    27         NSLog(@"wo ca lei ge da ye =======  4  
    ");
    28         NSLog(@"wo ca lei ge da ye =======  4  
    ");
    29     });
    30     
    31     NSLog(@"wo ca lei ge da ye =======  5  
    ");
    32     
    33     NSLog(@"wo ca lei ge da ye =======  6  
    ");

    打印结果

    2016-03-29 16:33:07.522 neeq_second[903:130796] wo ca lei ge da ye =======  1  

    2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

    2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

    2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

    2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

    2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

    2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

    2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

    2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

    2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  3  

    2016-03-29 16:33:07.524 neeq_second[903:130815] wo ca lei ge da ye =======  2  

    2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

    2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

    2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

    2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

    2016-03-29 16:33:07.525 neeq_second[903:130796] wo ca lei ge da ye =======  4  

    2016-03-29 16:33:07.525 neeq_second[903:130796] wo ca lei ge da ye =======  5  

    2016-03-29 16:33:07.525 neeq_second[903:130796] wo ca lei ge da ye =======  6  

    让明天,不后悔今天的所作所为
  • 相关阅读:
    JDK下载 安装 配置
    C#中的委托与事件 笔记
    转载 -- C# 中的委托和事件
    Laravel5 路由问题 /home页面无法访问
    eclipse的android智能提示设置
    svn在linux下的使用(ubuntu命令行模式操作svn)
    gdb结合coredump定位崩溃进程
    Android帧缓冲区(Frame Buffer)硬件抽象层(HAL)模块Gralloc的实现原理分析
    struct的初始化,拷贝及指针成员的使用技巧
    C++ 资源大全
  • 原文地址:https://www.cnblogs.com/-yun/p/5333498.html
Copyright © 2011-2022 走看看