QSDispatchQueue 1.0.1

QSDispatchQueue 1.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Aug 2017

Maintained by buaa0300.


Downloads

Total16
Week16
Month16

Installs

Apps7
Apps WeekApps This Week 7
powered by Segment

GitHub

Stars2
Watchers2
Forks1
Issues0
Contributors1
Pull Requests0

Code

Files2
LOCLines of Code 135


  • By
  • 南华coder

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