博客> 用多线程实现的顺序上传下载
用多线程实现的顺序上传下载
2017-11-24 15:50 评论:0 阅读:436 connorj
GCD GCD上传 多线程上传下载 顺序上传下载

利用线程组保证顺序上传下载, 希望能帮助到一些人对GCD的学习, 也请大神指点.

NSMutableArray *arr = [NSMutableArray arrayWithArray:@[@"1", @"2", @"3", @"4", @"5"]];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(queue, ^{

    dispatch_group_t group = dispatch_group_create();

    dispatch_queue_t sequalQueue = dispatch_queue_create("com.JC.queue", NULL);

    __block NSString *cc = @"";

    for (int i = 0; i < arr.count; i++) {
        dispatch_group_async(group, sequalQueue, ^{

            cc = [NSString stringWithFormat:@"%@+%@", cc, arr[i]];
            NSLog(@"%@, %d", cc, i);

        });
    }

    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        NSLog(@"~%@~", cc);
    });
});

dome:https://github.com/ConnorForGIT/CJDownloadManager

收藏
3
sina weixin mail 回到顶部