接口
Initializing an NSThread Object
Starting a Thread
Stopping a Thread
Determining the Thread’s Execution State
Working with the Main Thread
Querying the Environment
Working with Thread Properties
Working with Thread Priorities
注意点:在自己生成的线程里面要自己管理内存,其余应该是比较简单的,thread priorities的范围是0-1的小数,1的优先级最高,dictionary可以用来存放一些信息,比如在Foundation框架里面使用这个字典来存放NSConnection和NSAssertionHandler的实例
写个小demo
- (void)viewDidLoad { [superviewDidLoad]; NSNumber *oneNumb = [NSNumber numberWithInt:1]; NSThread *one = [[NSThreadalloc] initWithTarget:self selector:@selector(oneMethod:) object:oneNumb]; [one start]; [one setThreadPriority:0.8]; NSLog(@"one == %f", [one threadPriority]); } -(void)oneMethod:(NSNumber *)num { @autoreleasepool { // [NSThread sleepForTimeInterval:3]; // NSLog(@"-------exit"); // [NSThread exit]; NSLog(@"-------one = %d", [num intValue]); if (![[NSThreadcurrentThread] isMainThread]) { NSLog(@"-------sub thread"); } ; NSLog(@" addreass ---- %@ ------num = %d", [[NSThreadcallStackReturnAddresses] objectAtIndex:0],[[NSThreadcallStackReturnAddresses] count]); } }