iOS 多线程pthread 二

基本概念:

  • 简介
    • 语言:C
    • 线程声明周期:程序员管理
    • 使用频率:几乎不用
    • 一套通用的多线程API
    • 适用于Unix/Linux/Windows等系统
    • 跨平台、可移植性
    • 使用难度大

简单案列一

#import "ViewController.h"
#import <pthread.h>

@interface ViewController ()

@end

@implementation ViewController

void * run(void *param)
{
    for (NSInteger i = 0; i<50000; i++) {
        NSLog(@"------buttonClick---%zd--%@", i, [NSThread currentThread]);
    }
    return NULL;
}

- (IBAction)buttonClick:(id)sender {
    pthread_t thread;
    pthread_create(&thread, NULL, run, NULL);

    pthread_t thread2;
    pthread_create(&thread2, NULL, run, NULL);
}

@end

你可能感兴趣的:(多线程)