zoukankan      html  css  js  c++  java
  • GCD

    //

    //  ZBMainViewController.m

    //  TestProject

    //

    //  Created by 张先森 on 14/12/5.

    //  Copyright (c) 2014年 zhibin. All rights reserved.

    //

    #import "ZBMainViewController.h"

    @interface ZBMainViewController ()

    @end

    @implementation ZBMainViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

       // [self InitControls];

        

        [self InitControls];

    }

    //异步添加到并发队列 开启新线程

    -(void)InitControls{

        dispatch_queue_t  queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

        dispatch_async(queue, ^{

            NSLog(@"%@c测试1",[NSThread currentThread]);

        });

        dispatch_async(queue, ^{

                   NSLog(@"%@c测试2",[NSThread currentThread]);

        });

        dispatch_async(queue, ^{

                   NSLog(@"%@c测试3",[NSThread currentThread]);

        });

    }

    //异步添加到同步线程  会开启一个线程

    -(void)InitControls2{

        

        dispatch_queue_t queue=dispatch_queue_create("zhibin", NULL);

      

        dispatch_async(queue, ^{

              NSLog(@"%@c测试1",[NSThread currentThread]);

        });

        dispatch_async(queue, ^{

                      NSLog(@"%@c测试2",[NSThread currentThread]);

        });

        dispatch_async(queue, ^{

            

            NSLog(@"%@c测试3",[NSThread currentThread]);

        });

    }

    //同步添加到并发线程中  不开启新线程   线程失去并发能力

    -(void)InitControls3{

        dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

        

        

        dispatch_sync(queue, ^{

                    NSLog(@"%@c测试1",[NSThread currentThread]);

        });

        

        dispatch_sync(queue, ^{

                    NSLog(@"%@c测试2",[NSThread currentThread]);

        });

        

        dispatch_sync(queue, ^{

                    NSLog(@"%@c测试3",[NSThread currentThread]);

        });

    }

    //同步添加串行队列 不会开启新线程

    -(void)InitControls4{

        dispatch_queue_t  queue=dispatch_queue_create("zhibin", NULL);

        dispatch_sync(queue, ^{

                  NSLog(@"%@c测试1",[NSThread currentThread]);

        });

        dispatch_sync(queue, ^{

            NSLog(@"%@c测试2",[NSThread currentThread]);

        });

        dispatch_sync(queue, ^{

            NSLog(@"%@c测试3",[NSThread currentThread]);

        });

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    /*

    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

        // Get the new view controller using [segue destinationViewController].

        // Pass the selected object to the new view controller.

    }

    */

    @end

  • 相关阅读:
    mount error(12): Cannot allocate memory解决办法
    九死一生,技术人创业需要哪些前期准备?
    Wireshark抓包常见问题解析
    windows服务和进程的区别和联系
    Daemon Process
    C++11中的原子操作(atomic operation)
    Neo4j Cypher语法(一)
    UltraEdit快捷键大全 UltraEdit常用快捷键大全
    mysql查询优化之三:查询优化器提示(hint)
    如何解决tomcat中的应用报java.io.IOException: 您的主机中的软件中止了一个已建立的连接。
  • 原文地址:https://www.cnblogs.com/zhibin/p/4152201.html
Copyright © 2011-2022 走看看