GCD

// 异步串行队列

{

dispatch_queue_t Queue = dispatch_queue_create("queue", DISPATCH_QUEUE_SERIAL);

dispatch_async(Queue, ^{

});

}

//  异步并行队列

{

dispatch_queue_t Queue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT);

dispatch_async(Queue, ^{

});

}

// 同步串行队列

{

dispatch_queue_t Queue = dispatch_queue_create("queue", DISPATCH_QUEUE_SERIAL);

dispatch_sync(Queue, ^{

});

}

// 同步并行队列(同步不会自动创建线程,并行需要多个线程,所以还是串行队列)

{

dispatch_queue_t Queue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT);

dispatch_sync(Queue, ^{

});

}

// 异步主线程队列通信

{

dispatch_queue_t mianQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

dispatch_async(mianQueue, ^{

dispatch_async(dispatch_get_main_queue(), ^{

});

});

}

// group线程组

{

dispatch_group_t groupQueue = dispatch_group_create();

dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_SERIAL_INACTIVE);

dispatch_queue_t conQueue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT);

dispatch_queue_t mianQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

dispatch_group_async(groupQueue, queue, ^{

});

dispatch_group_async(groupQueue, conQueue, ^{

});

dispatch_group_async(groupQueue, mianQueue, ^{

});

dispatch_group_notify(groupQueue, dispatch_get_main_queue(), ^{

});

}

//

dispatch_queue_t mianQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

dispatch_apply(6, mianQueue, ^(size_t index) {

});

//

dispatch_queue_t Queue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT);

dispatch_async(Queue, ^{

});

dispatch_barrier_async(Queue, ^{

});

dispatch_async(Queue, ^{

});

你可能感兴趣的:(GCD)