多線程一NSThread

NSThread Objective-C的線程類

1)、創建線程

創建線程,並自動執行
[NSThread detachNewThreadSelector:@selector(doSomeThing) toTarget:self withObject:nil];

創建線程,不自動執行
[[NSThread alloc] initWithTarget:self selector:@selector(doSomeThing) object:nil];

2)、設置線程名

thread.name = @"線程名稱";

3)、執行線程

[thread start];

BOOL isExcuting 線程是否在執行

4)、函數內獲取當前線程

[NSThread currentThread];

5)、獲取主線程

[NSThread mainThread];

BOOL isMainThread是否爲主線程

6)、線程休眠

[NSThread sleepForTimeInterval:1.0f];  // 休眠幾秒

[NSThread sleepUntilDate:date]; // 休眠到指定時間

7)、線程退出

[NSThread exit];

8)、線程取消

[NSThread cancelled];

9)、線程通信

在子線程方法中執行
[self performSelector:@selector(function) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES];

10)、設置線程優先級

[thead setTheadPrioity:];

11)、線程函數調用棧地址

[thread callStackReturnAddresses]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章