多线程学习05-线程状态

来源:互联网 发布:南京大数据公司有哪些 编辑:程序博客网 时间:2024/06/12 16:51

学习多线程05(之前跟着小码哥视频学习了多线程,准备把学到的东西放到网上,便于参考。仅有视频,所以所有文字都是自己打的,同时也温习一下多线程)


控制线程的状态:

启动线程

-(void)start;

//进入就绪状态->运行状态.当线程任务执行完毕,自动进入死亡状态。

阻塞(暂停)线程

+ (void)sleepUntilDate:(NSDate *)date;

+ (void)sleepForTimeInterval:(NSTimeInterval)ti;

//进入阻塞状态

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    [NSThread detachNewThreadSelector:@selector(runMan) toTarget:self withObject:@"limin_ios"];}-(void)runMan{    NSLog(@"开始");    //让线程睡眠2秒(阻塞2秒)    [NSThread sleepForTimeInterval:2.0];//    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];//    [NSThread sleepUntilDate:[NSDate distantFuture]];    NSLog(@"结束");    //线程一旦死亡,不会再开启,只能创建新的线程。    [NSThread exit];}

博客原地址:http://blog.csdn.net/leemin_ios/article/details/51188945

0 0
原创粉丝点击