NSThread小笔记

 

 注意点:在自己生成的线程里面要自己管理内存,其余应该是比较简单的,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]);

    }

}

  

posted @ 2014-04-19 15:43  三江汇流  阅读(161)  评论(0编辑  收藏  举报