zoukankan      html  css  js  c++  java
  • NSRunloop-基本概念

     //  详细资料相关说明    http://www.dreamingwish.com/dream-2012/ios-multithread-program-runloop-the.html
    
    /********NSRunloop的基本感念********/
    Run loops 是线程相关的基础框架的一部分。一个run loop就是一个时间处理的循环,用来不停地调度工作以及处理输入事件。
    
    线程的生命周期存在五个状态:新建、就绪、运行、阻塞、死亡。
    
    NSRunloop 可以保持一个线程一直为活动状态,不会马上销毁掉。
    
    /********定时器在多线程的使用********/
    //  在多线程中使用定时器必须开启Runloop,因为只有开启Runloop保持线程为活动状态,才能保持定时器不断执行。
    //  实例:
    - (void)runThread {
        //  创建自动释放池
        NSAutoreleasePool *pool = [[nsautoreleasePool alloc]init];
        //  创建定时器
        [NSTimer scheduledTimerWithTimeInterval:1
                                         target:self
                                      @selector:(timeAction)
                                       userInfo:nil
                                        repeats:YES];
        //  开启Runloop来使线程保持存活状态
        [[NSRunloop currentRunloop] run];
        
        [pool release];
    }
  • 相关阅读:
    【Linux】ZeroMQ 在 centos下的安装
    ZeroMQ下载、编译和使用
    在Linux系统上安装Git
    Linux下python2.7安装pip
    [Tyvj1474]打鼹鼠
    [BZOJ2908]又是nand
    [SPOJ375]Qtree
    浅谈算法——树链剖分
    [BZOJ5368/Pkusc2018]真实排名
    [FJOI2007]轮状病毒
  • 原文地址:https://www.cnblogs.com/needly/p/3401061.html
Copyright © 2011-2022 走看看