zoukankan      html  css  js  c++  java
  • 多线程NSThread基本用法

     
     
    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
       
        //开启多线程方法一
    //    [self performSelectorInBackground:@selector(threadAction) withObject:nil];
       
        //开启多线程方法二
    //    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(threadAction) object:nil];
        //thread.name = @"thread1";
    //    NSLog(@"MAIN中:%@",thread);

    //    [thread start];
       
        //开启多线程方法三
    //    [NSThread detachNewThreadSelector:@selector(threadAction) toTarget:self withObject:nil];
       


       

        for (int i = 0; i < 50; i ++) {
            NSLog(@"main: %d",i);
        }
    }

    - (void)threadAction{
       
        NSThread *thread = [NSThread currentThread];
            NSLog(@"thread中:%@",thread);
       
        for (int i = 0 ; i < 50; i ++) {
            NSLog(@"thread:  %d",i);
           
            if (i==10) {
                [NSThread exit];
            }
           
            if ([NSThread isMultiThreaded]) {
                NSLog(@"是多线程");
            }
        }
    }

    @end
  • 相关阅读:
    postfix队列管理
    fdisk添加磁盘
    postfix日志分析pflogsumm
    ioctl接口内容操作
    linux 路由表设置 之 route 指令详解
    手把手教你用 Strace 诊断问题
    rtsp学习----海康RTSP客户端连接深入分析
    栈回溯技术
    objdump命令
    linux中的strip命令简介------给文件脱衣服
  • 原文地址:https://www.cnblogs.com/chillytao-suiyuan/p/4834124.html
Copyright © 2011-2022 走看看