Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
執行緒
|
245
printf("The TIDs are equal!\n");
else
printf("The TIDs are unequal!\n");
終止執行緒
執行緒建立的反向操作是執行緒終止。執行緒終止類似於行程終止,只差在執行緒終止
時,行程中的其餘執行緒仍會繼續執行。在某些執行緒模式中,像是每連線執行緒(見
7 章〈每連線執行緒〉一節),執行緒會被頻繁地建立和銷毀。
執行緒在幾種情況下可能會終止執行,所有這些情況皆類似於行程的終止:
如果一個執行緒從它的起始常式(start routine)返回。這類似於
main()
的遇尾返回
falling off the end)。
如果一個執行緒調用了
pthread_exit()
函式(隨後會討論到),它就會終止執行。這
類似於叫用
exit()
如果一個執行緒被另一個執行緒經由
pthread_cancel()
給取消了,它就會終止執行。
這類似於經由
kill()
傳送
SIGKILL
信號。.
這三個例子只會殺掉當前的執行緒。在下列情況中,一個行程裡的所有執行緒都會被殺
掉,這因而會殺掉整個行程:
行程從它的
main()
函式返回。.
行程經由
exit()
終止執行。
行程經由
execve()
執行一個新的二元映像(binary image)。
信號可以殺掉一個行程或是個別的執行緒,這取決於信號的發送方式。Pthread 讓信號
的處理變得相當複雜;在多執行緒程式中最好儘量減少信號的使用。第 10 章對信號有
完整的說明。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812