Latest 0.1.2
Homepage https://github.com/xiongzenghuidegithub/ZHGCDDispatcher
License MIT
Platforms ios 8.0, requires ARC
Frameworks Foundation
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

This library requires iOS 8.0+ and Xcode 8.0+.

Installation

ZHGCDDispatcher is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'ZHGCDDispatcher'

Usage

for (int i = 0; i < 100; i++) {
    switch ((i%5)) {
        case 0: {
            ZHAsyncWithQOSUserInteractive(^{
                NSLog(@"task %d: %@", i, [NSThread currentThread]);
            });
        }
            break;
        case 1: {
            ZHAsyncWithQOSUserInitiated(^{
                NSLog(@"task %d: %@", i, [NSThread currentThread]);
            });
        }
            break;
        case 2: {
            ZHAsyncWithQOSUtility(^{
                NSLog(@"task %d: %@", i, [NSThread currentThread]);
            });
        }
            break;
        case 3: {
            ZHAsyncWithQOSBackgroud(^{
                NSLog(@"task %d: %@", i, [NSThread currentThread]);
            });
        }
            break;
        case 4: {
            ZHAsyncWithQOSDefault(^{
                NSLog(@"task %d: %@", i, [NSThread currentThread]);
            });
        }
            break;
    }
}

Concurrent queue may cause the number of threads to increase

dispatch_get_global_queue()

ZHGCDDispatcher

dispatch_queue_create(label, concurrent)

ZHGCDDispatcher

conclusion

You should avoid using concurrent queues at will.

Serial queue the same may caused

  • 1、Dead loop creation serial queue
  • 2、Frequent creation and destruction of heavyweight objects(AVPlayer、AVPlayerLayer …)

Controlling thread concurrency

  • 1、Using pool mechanism to control the maximum concurrent number of threads
  • 2、Because most of the CPU tasks in mobile terminal app do not consume much time.
  • 3、so don’t need too many threads
  • 4、But because of too many threads, CPU switching and resource competition loss performance are caused.
  • 5、Avoid frequent creation and destruction of threads, and control the number of concurrent threads, both to meet the number of concurrent CPU, and not because of too many threads lead to performance losses

Author

xiongzenghui, [email protected]

License

ZHGCDDispatcher is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ZHGCDDispatcher",
    "version": "0.1.2",
    "summary": "wrapper basic on YYDispatchQueuePool, avoid thread count too many!!!.",
    "homepage": "https://github.com/xiongzenghuidegithub/ZHGCDDispatcher",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "xiongzenghui": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/xiongzenghuidegithub/ZHGCDDispatcher.git",
        "tag": "0.1.2"
    },
    "source_files": "ZHGCDDispatcher/**/*.{h,m}",
    "public_header_files": "ZHGCDDispatcher/**/*.h",
    "requires_arc": true,
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This