ios多线程操作(四)—— GCD核心概念
- (void)viewDidLoad { [super viewDidLoad]; // 获得全局队列 dispatch_queue_t q = dispatch_get_global_queue(0, 0); // 执行同步任务 dispatch_sync(q, ^{ // 让执行该任务的线程休眠2s [NSThread sleepForTimeInterval:2.0]; NSLog(@"block - %@",[NSThread currentThread]); }); NSLog(@"viewDidLoad - %@",[NSThread currentThread]); }
- (void)viewDidLoad { [super viewDidLoad]; // 获得全局队列 dispatch_queue_t q = dispatch_get_global_queue(0, 0); // 执行异步任务 dispatch_async(q, ^{ // for (int i = 0; i<10; i++) { NSLog(@"block - %@ - %d",[NSThread currentThread],i); } }); NSLog(@"viewDidLoad - %@",[NSThread currentThread]); }
- (void)viewDidLoad { [superviewDidLoad]; //获得全局队列 dispatch_queue_t q =dispatch_get_global_queue(0, 0); //执行异步任务 for (int i = 0; i< 10; i++) { dispatch_async(q, ^{ NSLog(@"block - %@ - %d",[NSThreadcurrentThread],i); }); } NSLog(@"viewDidLoad - %@",[NSThreadcurrentThread]); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。