zoukankan      html  css  js  c++  java
  • iOS多线程

    进程:一个正在运行的程序看作进程,它拥有独立运行所需的全部资源。(正在运行的qq)

    线程:程序中独立运行的代码段。(接收qq消息的代码)

    开辟一个主线程占1M,开辟一个子线程512kb。

    //thread_1回调方法
    - (void)thread_1Action:(NSString *)sender
    {
        //当子线程是我们手动开辟的,那么就需要我们自己来管理内存
        @autoreleasepool {
            NSLog(@"thread_1_Info%@",[NSThread currentThread]);
            NSLog(@"参数:%@",sender);
        }
    }
    
    - (void)thread_2Action
    {
        @autoreleasepool {
            NSLog(@"Thread_2--%@",[NSThread currentThread]);
        }
        
    }
    
    - (void)thread_3Action
    {
        @autoreleasepool {
            NSLog(@"Thread_3333--%@",[NSThread currentThread]);
        }
        
    }
    //nsthread 学习
    -(void)threadStudy
    {
        //通过便利构造器的方式创建thread对象,不用手动启动
        [NSThread detachNewThreadSelector:@selector(thread_1Action:) toTarget:self withObject:@"thread_1"];
        //通过alloc方式创建
        NSThread *thread_2 = [[NSThread alloc] initWithTarget:self selector:@selector(thread_2Action) object:nil];
        thread_2.name = @"Thread_2";
        [thread_2 start];
        thread_2.threadPriority = 1.0;
        
        NSThread *thread_3 = [[NSThread alloc] initWithTarget:self selector:@selector(thread_3Action) object:nil];
        thread_3.name = @"thread_3";
        [thread_3 start];
        
    }
  • 相关阅读:
    java 下载图片并传输(java自带 BASE64工具进行图片和字符串转换)
    MySQL的日期格式
    eclipse下查看maven下载的源码中文乱码问题
    Linux----部署
    python----logging
    python----pymysql
    vmware15 激活秘钥
    vmware15 激活秘钥
    Ubuntu18.04安装
    msyql45讲 20--幻读是什么,幻读有什么问题?
  • 原文地址:https://www.cnblogs.com/ios988/p/5291162.html
Copyright © 2011-2022 走看看