Latest 1.0.1
Homepage https://github.com/buaa0300/QSDispatchQueue
License MIT
Platforms ios 7.0, requires ARC
Authors

A Way to control maxConcurrentCount of GCD concurrent queue by dispatch_semaphore(利用GCD的信号量机制实现控制GCD并发队列最大并发数的方案)

Installation

pod 'QSDispatchQueue'

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

Then 

#import "QSDispatchQueue.h"

Usage-Demo1

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);
    }];
}

Usage-Demo2

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);
    }];
}

Relation

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

Latest podspec

{
    "name": "QSDispatchQueue",
    "version": "1.0.1",
    "summary": "A way to control maxConcurrentCount of GCD concurrent queue",
    "homepage": "https://github.com/buaa0300/QSDispatchQueue",
    "license": "MIT",
    "authors": {
        "u5357u534ecoder": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/buaa0300/QSDispatchQueue.git",
        "tag": "1.0.1"
    },
    "requires_arc": true,
    "source_files": "QSDispatchQueue/*.{h,m}"
}

Pin It on Pinterest

Share This