1. 程式人生 > >GCD的簡單使用,開闢一條新的執行緒,讓上面的任務序列執行

GCD的簡單使用,開闢一條新的執行緒,讓上面的任務序列執行

// 1.獲得全域性的併發佇列

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    // 2.將任務加入佇列

    dispatch_async(queue, ^{

        for (NSInteger i = 0; i<10; i++) {

            NSLog(@"1-----%@", [NSThread currentThread]);

        }

    });

    dispatch_async(queue, ^{

        for (NSInteger i = 0; i<10; i++) {

            NSLog(@"2-----%@", [NSThread currentThread]);

        }

    });

    dispatch_async(queue, ^{

        for (NSInteger i = 0; i<10; i++) {

            NSLog(@"3-----%@", [NSThread currentThread]);

        }

    });