#import <pthread.h>
// 创建线程
pthread_t myRestrict;
pthread_create(&myRestrict, NULL, run, NULL);
void *run(void *data)
{
for (int i = 0; i<10000; i++) {
NSLog(@"touchesBegan----%d-----%@", i, [NSThread currentThread]);
}
return NULL;
}
3.完整的代码
//
// HMViewController.m
// 02-pthread(演示)
//
#import "HMViewController.h"
#import <pthread.h>
@interface HMViewController ()
@end
@implementation HMViewController
void *run(void *data)
{
for (int i = 0; i<10000; i++) {
NSLog(@"touchesBegan----%d-----%@", i, [NSThread currentThread]);
}
return NULL;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 创建线程
pthread_t myRestrict;
pthread_create(&myRestrict, NULL, run, NULL);
}
@end
原文地址:http://blog.csdn.net/fan_yufan/article/details/46289491