NSThread 多线程 三种方式

//

//  ZBMainViewController.m

//  TestProject

//

//  Created by 张先森 on 14/12/5.

//  Copyright (c) 2014年 zhibin. All rights reserved.

//

 

#import "ZBMainViewController.h"

 

@interface ZBMainViewController ()

@property(nonatomic,strong)CALayer *mylayer;

 

 

@end

 

@implementation ZBMainViewController

 

 

 

 bool isopen=NO;

 

 

- (void)viewDidLoad {

    [super viewDidLoad];

 

    [self InitControls];

}

 

-(void)InitControls{

    NSThread *thread=[NSThread currentThread];

    NSLog(@"%@",thread);

    NSThread *mainthread=[NSThread mainThread];

    NSLog(@"%@",mainthread);

    

    

    NSThread *tempthread=[[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"线程1"];

    tempthread.name=@"thread1";

    

    [tempthread start];

    

    

    

    

    [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"线程2"];

    

    

    

    

    [self performSelectorInBackground:@selector(run:) withObject:@"线程3"];

}

 

-(void)run:(NSString *)str{

 

    NSLog(@"%@",str);

 

 

 

}

 

 

 

 

 

 

@end

 

posted @ 2014-12-09 00:09  銱ル╬鎯噹  阅读(107)  评论(0编辑  收藏  举报