您的位置:首页 > 其它

刀哥多线程之gcd-01-sync&async

2015-08-15 20:32 423 查看

同步 & 异步

概念

同步

必须等待当前语句执行完毕,才会执行下一条语句

异步

不用等待当前语句执行完毕,就可以执行下一条语句

NSThread
中的
同步
&
异步

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"start");

// 同步执行
//    [self demo];
// 异步执行
[self performSelectorInBackground:@selector(demo) withObject:nil];

NSLog(@"over");
}

- (void)demo {

NSLog(@"%@", [NSThread currentThread]);
[NSThread sleepForTimeInterval:1.0];
NSLog(@"demo 完成");
}


代码小结

同步
从上到下顺序执行

异步
多线程的代名词
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: