您的位置:首页 > 移动开发 > IOS开发

iOS多线程

2016-03-18 10:45 567 查看
进程:一个正在运行的程序看作进程,它拥有独立运行所需的全部资源。(正在运行的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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: