zoukankan      html  css  js  c++  java
  • OC 线程操作

    - (void)forDemo{
        //全都是在主线程操作的
        for (NSInteger i = 0; i<10; i++) {
            NSLog(@"--%@", [NSThread currentThread]);
        }
        
        /*
         2018-06-27 11:33:44.226664+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.226845+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.227048+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.227711+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.227796+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.227927+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.227986+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.228046+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.228111+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         2018-06-27 11:33:44.228165+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
         */
    }
    
    -(void)GCD_apply{
        
        
        /**
         参数1:size_t iterations 便利次数
         参数1:dispatch_queue_t  _Nonnull queue 队列:只能穿进去并发队列,主队列 会死锁 ,串行队列和for循环一样效果在主队列,
         参数1:<#^(size_t)block#> ^(size_t 索引) {
         
         }
         
          主队列也会参与这个操作, 并发执行
         */
        dispatch_apply(10, dispatch_get_global_queue(0, 0), ^(size_t index) {
            NSLog(@"dispatch_get_global_queue ---- %zd--%@", index,[NSThread currentThread]);
        });
        
        
        dispatch_queue_t queue = dispatch_queue_create("并发", DISPATCH_QUEUE_CONCURRENT);
        dispatch_apply(10, queue, ^(size_t index) {
            NSLog(@"DISPATCH_QUEUE_CONCURRENT ---- %zd--%@", index,[NSThread currentThread]);
        });
        
        /*
         2018-06-27 11:41:46.924361+0800 5线程操作-GCD-快速迭代[7877:85649] 0--<NSThread: 0x608000074ac0>{number = 1, name = main}
         2018-06-27 11:41:46.924467+0800 5线程操作-GCD-快速迭代[7877:85688] 2--<NSThread: 0x60400007de40>{number = 4, name = (null)}
         2018-06-27 11:41:46.924468+0800 5线程操作-GCD-快速迭代[7877:85691] 3--<NSThread: 0x60c000465cc0>{number = 5, name = (null)}
         2018-06-27 11:41:46.924469+0800 5线程操作-GCD-快速迭代[7877:85690] 1--<NSThread: 0x608000265a00>{number = 3, name = (null)}
         2018-06-27 11:41:46.924526+0800 5线程操作-GCD-快速迭代[7877:85649] 4--<NSThread: 0x608000074ac0>{number = 1, name = main}
         2018-06-27 11:41:46.924554+0800 5线程操作-GCD-快速迭代[7877:85688] 5--<NSThread: 0x60400007de40>{number = 4, name = (null)}
         2018-06-27 11:41:46.924568+0800 5线程操作-GCD-快速迭代[7877:85691] 6--<NSThread: 0x60c000465cc0>{number = 5, name = (null)}
         2018-06-27 11:41:46.924602+0800 5线程操作-GCD-快速迭代[7877:85649] 8--<NSThread: 0x608000074ac0>2018-06-27 11:41:46.924639+0800 5线程操作-GCD-快速迭代[7877:85688] 9--<NSThread: 0x60400007de40>{number = 4, name = (null)}
         {number = 1, name = main}
         2018-06-27 11:41:46.924604+0800 5线程操作-GCD-快速迭代[7877:85690] 7--<NSThread: 0x608000265a00>{number = 3, name = (null)}
         */
    }
  • 相关阅读:
    OpenCV中的霍夫线变换和霍夫圆变换
    霍夫圆变换
    异或的性质及运用
    不用中间变量交换两个数值变量的值
    图像变换
    STM32程序的启动
    RAM与FLASH
    STM8的AIR与STM32的Keil的指定地址存数据
    HEX与ASCII之间装换
    STM32、Cortex-A、Cortex-R、Cortex-M、SecurCore
  • 原文地址:https://www.cnblogs.com/qingzZ/p/9237408.html
Copyright © 2011-2022 走看看