美文网首页
面试题考察输出结果

面试题考察输出结果

作者: zaijianbali | 来源:发表于2022-06-02 16:20 被阅读0次
    - (void)testAsync3{
      //注意这个地方是全局队列,dispatch_get_global_queue
      dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
      
      for (int i = 0; i<100; i++) {
          dispatch_async(queue, ^{
              NSLog(@"%@",@(i));
          });
      }
      dispatch_barrier_async(queue, ^{
          NSLog(@"a");
      });
      NSLog(@"b");
      
      for (int i = 0; i< 100; i++) {
          dispatch_async(queue, ^{
              NSLog(@"%@",@(i));
          });
      }
    }
    - (void)testAsync2{
      dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT);
      NSMutableArray *a = [NSMutableArray array];
      for (int i = 0; i< 100; i++) {
          dispatch_async(queue, ^{
              [a addObject:@(i)];
          });
      }
      NSLog(@"%@",a);
    }
    

    相关文章

      网友评论

          本文标题:面试题考察输出结果

          本文链接:https://www.haomeiwen.com/subject/vxmqmrtx.html