//
// Created by apple on 14-6-23.
// Copyright (c) 2014年 itcase. All rights reserved.
//
#import "YYViewController.h"
#import <pthread.h>
@interface YYViewController ()
- (IBAction)btnClick;
@end
@implementation YYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
//按钮的点击事件
- (IBAction)btnClick {
//1.获取当前线程
NSThread *current=[NSThread currentThread];
//主线程
NSLog(@"btnClick----%@",current);
//2.使用for循环执行一些耗时操作
pthread_t thread;
pthread_create(&thread, NULL, run, NULL);
}
//c语言函数
void *run(void *data)
{
//获取当前线程,是新创建出来的线程
NSThread *current=[NSThread currentThread];
for (int i=0; i<10000; i++) {
NSLog(@"btnClick---%d---%@",i,current);
}
return NULL;
}
//多个线程,点击按钮执行按钮调用方法的时候,主线程没有被阻塞
@end
实现效果:
打印结果:











