iOS多线程(一)-- pthread

2016-05-14  本文已影响77人  eightzg

pthread是C语言的多线程解决方案,线程的生命周期需要程序员管理,在开发中几乎不用,读者可以作为了解。

#import <pthread.h>
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 创建线程
    pthread_t thread;  //1
    pthread_create(&thread, NULL, run, NULL);  //2
}
void *run(void *data)
{
    for (int i = 0; i<10000; i++) {
        NSLog(@"touchesBegan----%d-----%@", i, [NSThread currentThread]);
    }
    return NULL;
}
Paste_Image.png

尽管pthread不是主流的多线程实现方案,但是作为优秀的程序员还是有必要了解一下的~在接下来的几篇教程中会继续讲解另外三种多线程的实现方案。

上一篇 下一篇

猜你喜欢

热点阅读