#import <pthread.h>
@interface HMViewController ()
- (IBAction)btnClick;
@end
@implementation HMViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
void *run(void *data) {
NSThread *current = [NSThread currentThread];
for (int i = 0; i<20000; i++) {
NSLog(@"run---%@", current);
}
return NULL;
}
- (IBAction)btnClick {
// 1.获得当前的线程
NSThread *current = [NSThread currentThread];
NSLog(@"btnClick---%@", current);
// 2.执行一些耗时操作 : 创建一条子线程
pthread_t threadId;
pthread_create(&threadId, NULL, run, NULL);
}
@end