#import "ViewController.h"
#import <pthread.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
pthread_t ID;
NSString *name = @"hehe";
/*
参数一:线程的编号(地址)
参数二:线程的属性
参数三:要调用的函数名
参数四:函数的参数
*/
// int result = pthread_create(&ID,NULL,demo,NULL);
//带参数的用法
int result = pthread_create(&ID,NULL,demo,(__bridge void *)(name));
if (result == 0) {
NSLog(@"成功");
}
else
{
NSLog(@"失败");
}
}
void* demo(void* param)
{
NSString *str = (__bridge NSString *)(param);
NSLog(@"demo %@------%@",[NSThread currentThread],str);
return NULL;
}
@end