首页 > 技术文章 > GCD(1)

wukun16 2015-10-16 05:07 原文

//

//  ViewController.m

//  UI-NO-26

//

//  Created by Bruce on 15/8/28.

//  Copyright (c) 2015年 Bruce. All rights reserved.

//

 

#import "ViewController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

//    死锁 在主队列(GCD)里面  在主线程(UI线程)同步执行任务

//    主队列  跟  主线程  是一个东西

//    同步执行  一个任务完毕之后  才会去执行另外一个任务

    

//    主队列(GCD)《同步执行》某个任务的时候  会等待前面的任务 执行完毕之后 再去执行  主队列里面的任务

//    但是  主队列 是在  主线程里面  执行任务的  《他们两个现在 在同一个线程里面》   线程 是顺序执行任务的   这时候 主线程 会等主队列里面的任务执行完毕  再去继续执行,    主队列  会等待  主线程  执行完毕  才回去执行 主队列 里面的任务

    

//    通过GCD 获得主队列 dispatch_get_main_queue

//    所有接收队列对象  都用dispatch_queue_t

//    dispatch_queue_t mainQueue =  dispatch_get_main_queue();

    /*

    NSLog(@"主线程执行到这暂停 等待主队列 执行");

//    同步执行任务 dispatch_sync

    dispatch_sync(mainQueue, ^{

        NSLog(@"主队列 等待 主线程  执行完毕之后  再执行");

    });

    

    NSLog(@"

推荐阅读