iOS多线程

本文详细介绍了在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];
    
}

 

转载于:https://www.cnblogs.com/ios988/p/5291162.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值