用pthread创建多线程(了解)

Posted on 2016-07-16 17:26  柠檬片  阅读(253)  评论(0)    收藏  举报
 1 - (IBAction)btnClick:(id)sender {
 2     
 3     NSLog(@"%@",[NSThread mainThread]);
 4     //创建线程
 5     pthread_t thread;
 6     /*
 7      第一个参数:线程对象
 8      第二个参数:线程属性
 9      第三个参数:void *(*)(void *) 指向函数的指针
10      第四个参数:函数的参数
11      */
12     pthread_create(&thread, NULL, run, NULL);
13     
14     pthread_t thread1;
15     pthread_create(&thread1, NULL, run, NULL);
16 }
17 //void *(*)(void *)
18 void *run(void *param)
19 {
20 //    NSLog(@"---%@-",[NSThread currentThread]);
21     for (NSInteger i =0 ; i<10000; i++) {
22         NSLog(@"%zd--%@-",i,[NSThread currentThread]);
23     }
24     return NULL;
25 }
用pthread创建多线程