int pthread_join (pthread_t thread, void **retval);
調用成功時,進行調用的執行緒會遭到阻擋,直到
thread
所指定的執行緒終止執行(如
果
thread
已經終止執行,
pthread_join()
會立即返回)。一旦
thread
終止執行,進行
調用的行程會被喚醒,如果
retval
的值不是
NULL
,其所提供的是被終止執行緒傳遞給
pthread_exit()
的傳回值,或是起始常式的傳回值。然後我們會說執行緒被連接在一起
了。連接功能讓執行緒的執行得以跟其他執行緒的生命週期同步。Pthread 中所有執行緒
都是對等的;任何執行緒都可以連接任何其他執行緒。單一執行緒可以連接許多執行緒
(事實上,正如我們將看到的,這往往是主要執行緒等待其所建立之執行緒的方式),
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.