您的位置:首页 > 编程语言 > C语言/C++

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: