zoukankan      html  css  js  c++  java
  • IOS 多线程-pthread

    #import <pthread.h>
    
    @interface HMViewController ()
    - (IBAction)btnClick;
    
    @end
    
    @implementation HMViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    void *run(void *data) {
        
        NSThread *current = [NSThread currentThread];
        
        for (int i = 0; i<20000; i++) {
            NSLog(@"run---%@", current);
        }
        
        return NULL;
    }
    
    - (IBAction)btnClick {
        // 1.获得当前的线程
        NSThread *current = [NSThread currentThread];
        NSLog(@"btnClick---%@", current);
        
        // 2.执行一些耗时操作 : 创建一条子线程
        pthread_t threadId;
        pthread_create(&threadId, NULL, run, NULL);
    }
    @end
  • 相关阅读:
    冲刺2 05
    冲刺02 04
    人月神话阅读笔记01
    进度条
    团队冲刺第十天
    团队冲刺第九天
    学习进度条13
    团队冲刺第八天
    怎样买书更便宜
    冲刺第七天
  • 原文地址:https://www.cnblogs.com/liuwj/p/6601928.html
Copyright © 2011-2022 走看看