GCD三种队列

1:dispatch_get_global_queue 后台执行队列
2:dispatch_get_main_queue  主队列
3:dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT)  自定义队列:其中第二个参数为DISPATCH_QUEUE_CONCURRENT的时候是并行发执行,为NULL的是串发执行

- (IBAction)sendBtnClick:(UIButton *)sender {

    dispatch_queue_t myQueue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(myQueue, ^{
        
        sleep(2);
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [self updateLabel];
        });

    });
   
    
    dispatch_queue_t defineQueue=dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT);
    dispatch_async(defineQueue, ^{
        
        [self sendState];
    });
    
}
-(void)sendState
{
    sleep(2);
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self updateLabel];
    });
}
-(void)updateLabel
{
   _remindLabel.text=@"发送成功";
}

 

posted @ 2015-03-29 18:24  曹县三胖暴打大猩猩  阅读(184)  评论(0编辑  收藏  举报