• GCD可以设置线程最大并发量


    -(void)dispatchSignal{

        //crate的value表示,最多几个资源可访问
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(2);   
        dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
         
        //任务1
        dispatch_async(quene, ^{
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
            NSLog(@"run task 1");
            sleep(1);
            NSLog(@"complete task 1");
            dispatch_semaphore_signal(semaphore);       
        });<br>
        //任务2
        dispatch_async(quene, ^{
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
            NSLog(@"run task 2");
            sleep(1);
            NSLog(@"complete task 2");
            dispatch_semaphore_signal(semaphore);       
        });<br>
        //任务3
        dispatch_async(quene, ^{
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
            NSLog(@"run task 3");
            sleep(1);
            NSLog(@"complete task 3");
            dispatch_semaphore_signal(semaphore);       
        });   
    }
  • 相关阅读:
    UVA10302 【Summation of Polynomials】
    小Z 系列 解题报告
    Dsu on tree
    轻重链剖分
    二分图匹配
    题解 P2455 【[SDOI2006]线性方程组】
    闫氏DP分析法
    扩展域并查集
    bindColumn、bindParam与bindValue的区别
    如何获取二维数组的列数
  • 原文地址:https://www.cnblogs.com/dashengios/p/10694945.html
Copyright © 2020-2023  润新知