1.牛逼的中枢调度器,纯C语言。
2.优势。
1.为多核运算提供的解决方案,他可以自动利用CPU的内核。
2.会自动管理线程的生命周期,创建线程,调度任务,销毁线程。
3.任务:执行什么操作。
4.队列:用来存放任务。
5.GCD使用的两个步骤。
1.定制任务
2.将任务添加到队列中。
1.GCD会自动将队列中的任务取出,放到对应的线程中执行。
2.任务的取出遵循队列原则。
6.执行任务。
7.队列的类型。
8.
#import "HMViewController.h"
@interface HMViewController ()
@end
@implementation HMViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// dispatch_sync : 同步,不具备开启线程的能力
// dispatch_async : 异步,具备开启线程的能力
// 并发队列 :多个任务可以同时执行
// 串行队列 :一个任务执行完后,再执行下一个任务
// 获得全局的并发队列
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// 将 任务 添加 全局队列 中去 异步 执行
dispatch_async(queue, ^{
NSLog(@"-----下载图片1---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"-----下载图片2---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"-----下载图片3---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"-----下载图片4---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"-----下载图片5---%@", [NSThread currentThread]);
});
}
@end