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
  • 相关阅读:
    Linux命令-查看进程
    Linux命令-查看内存
    Linux命令---vim
    oracle分页查询按日期排序失败问题
    oracle使用between and边界问题
    给大家介绍一个自我感觉好用的网站
    想学习一下微服务
    oracle获取年、月、日
    mybatis返回map结果集
    修改表中列
  • 原文地址:https://www.cnblogs.com/chillytao-suiyuan/p/4834124.html
Copyright © 2011-2022 走看看