QSDispatchQueue 1.0.1

QSDispatchQueue 1.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年8月

buaa0300维护。



  • 南华coder

通过 dispatch_semaphore 控制GCD并发队列的最大并发数(maxConcurrentCount)的方法

安装

pod 'QSDispatchQueue'

OR put QSDispatchQueue.h and QSDispatchQueue.m into your project directly.

Then 

#import "QSDispatchQueue.h"

使用示例1

dispatch_queue_t workConcurrentQueue = dispatch_queue_create("com.jzp.async.queue", DISPATCH_QUEUE_CONCURRENT);
QSDispatchQueue *queue = [[QSDispatchQueue alloc]initWithQueue:workConcurrentQueue concurrentCount:3];
for (NSInteger i = 0; i < 10; i++) {
    [queue async:^{
        NSLog(@"thread-info:%@开始执行任务%d",[NSThread currentThread],(int)i);
        sleep(1);
        NSLog(@"thread-info:%@结束执行任务%d",[NSThread currentThread],(int)i);
    }];
}

使用示例2

dispatch_queue_t workConcurrentQueue = dispatch_queue_create("com.jzp.sync.queue", DISPATCH_QUEUE_CONCURRENT);
QSDispatchQueue *queue = [[QSDispatchQueue alloc]initWithQueue:workConcurrentQueue concurrentCount:1];
for (NSInteger i = 0; i < 10; i++) {
    [queue sync:^{
        NSLog(@"thread-info:%@开始执行任务%d",[NSThread currentThread],(int)i);
        sleep(1);
        NSLog(@"thread-info:%@结束执行任务%d",[NSThread currentThread],(int)i);
    }];
}

关系

http://www.jianshu.com/p/5d51a367ed62