多线程:同步的作用
2016-03-25 23:27
225 查看
// // ViewController.m // 10-同步的作用 // // Created by gzxzmac on 16/1/29. // Copyright © 2016年 gzxzmac. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self gcdDemo]; } /* 1. 同步的作用:先做某些事情,做完之后再去做其他的(比如先登录,再下载(扣费)) */ // 先登录再下载 - (void)gcdDemo { // 创建并发队列 dispatch_queue_t queue = dispatch_queue_create("itcast", DISPATCH_QUEUE_CONCURRENT); dispatch_async(queue, ^{ // 登录 dispatch_sync(queue, ^{// 如果网络慢, NSLog(@"登录..%@", [NSThread currentThread]); }); // 下载文件A,B dispatch_async(queue, ^{ NSLog(@"下载文件A %@",[NSThread currentThread]); }); dispatch_async(queue, ^{ NSLog(@"下载文件B %@",[NSThread currentThread]); }); }); } @end
相关文章推荐
- 删除docker0网卡
- 网络编程常见问题总结
- execute、executeQuery和executeUpdate之间的区别
- MySql与SqlServer的一些常用用法的差别
- Oracle11g release2数据导出到Oracle10g release2方法
- 多线程:主队列
- 多线程:并发队列
- mvn profiles
- linux中断系统那些事之----中断处理过程【转】
- 那些年前端经典面试题
- ftrace 的使用【转】
- 项目已经部署,tomcat已经启动,网址也没问题,却出现404错误
- 弦月下的SQL<4> SQL语言基础
- 代码大全_第3部分: 变量
- Android OkHttp完全解析 是时候来了解OkHttp了
- 多线程:串行队列
- wget完成ftp链接下载
- iOS系统原生二维码条形码扫描
- UVALIVE 3516(DP)
- google工具包