iOS多線程實現1-pthread,ios多線程1-pthread

來源:互聯網
上載者:User

iOS多線程實現1-pthread,ios多線程1-pthread

  一套通用的多線程API,採用C語言編寫,跨平台\可移植,適用於Unix\Linux\Windows等系統,但是使用起來難度比較大,生命週期也是由程式員來管理。在iOS編程中很少使用這種方法。

#import <pthread.h>/// 點擊螢幕建立一個線程- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    pthread_t thread; //建立線程    NSString *str = @"helloWorld"; //建立參數    // 參數1  線程編號的地址    // 參數2  線程的屬性    // 參數3  線程要執行的函數(函數指標)(第三個參數可以,demo,*demo, 一般用&demo)    // 參數4  線程要執行的函數的參數    int result = pthread_create(&thread, NULL, &demo, (__bridge void *)(str));    // __bridge  oc類型到c語言類型的一個轉換    // void *p = (__bridge void *)(str);    NSLog(@"over %d",result);}/// 線程要執行的函數  傳參數void *(demo)(void *param){    NSString *str = (__bridge NSString *)(param);    NSLog(@"%@",str);    return NULL;}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.