C语言 pthread的使用
2016-05-21 21:49
489 查看
#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
#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
相关文章推荐
- -i++与i的值问题
- c++拾遗-----函数探幽
- 【VS开发】C++异常处理操作
- C++中的name mangling
- GeekBand c++學習筆記之二(帶指針的class中的必須要學的-Big Three法則)
- 2015第六届蓝桥杯B组C/C++决赛题解【2.5.6待解><】
- C++ 中类模板
- C++primer_第五章_语句_学习跟踪
- C++之命名空间
- C++静态库基本编程
- C++primer_第四章_表达式_学习跟踪
- 九度 OJ 1020:最小长方形
- C++函数名的修饰规则
- C语言函数内static关键字详解
- C++ #define用法总结
- 九度 OJ 1046:求最大值
- 多重部分和问题
- C++、python 写类似全排列算法
- POJ 2392-Space Elevator(多重部分和-多重背包)
- C语言中fclose函数