码迷,mamicode.com
首页 > 编程语言 > 详细

线程状态

时间:2015-06-14 10:55:28      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

@interface HMViewController ()
@property (nonatomic, strong) NSThread *thread;
@end

@implementation HMViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil];
    self.thread.name = @"线程A";
}

- (void)test
{
    NSLog(@"test - 开始 - %@", [NSThread currentThread].name);
    
//    [NSThread sleepForTimeInterval:5]; // 阻塞状态
    
//    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:5.0];
//    [NSThread sleepUntilDate:date];
    
    for (int i = 0; i<1000; i++) {
        NSLog(@"test - %d - %@", i, [NSThread currentThread].name);
        
        if (i == 50) {
            [NSThread exit];
        }
    }
    
    NSLog(@"test - 结束 - %@", [NSThread currentThread].name);
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 开启线程
    [self.thread start];
}

@end

 

线程状态

标签:

原文地址:http://www.cnblogs.com/cnios/p/4574716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!