//
// 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
多线程:同步的作用
最新推荐文章于 2022-07-07 00:09:20 发布