2017-04-12 83 views
1

在Solaris中,thr_join文件規定如下:的Solaris thr_join VS POSIX在pthread_join

int thr_join(thread_t thread, thread_t *departed, void 
    **status); 
If the target thread ID is 0, thr_join() finds and returns 
    the status of a terminated undetached thread in the process. 

是POSIX pthread_join等同?

int pthread_join(pthread_t thread, void **status); 

,直到目標線程完成 如何使用在pthread_join在thr_join的情況下,我想知道哪些子線程中許多已經終止掛起調用線程的處理。 有沒有其他的選擇? 換句話說,如果一個父線程產生N個子線程,那麼父線程如何通過輪詢或其他線程知道哪個線程已退出/終止?

回答

0

POSIX pthread_join是否等同?

是的,它是等價的。那麼,足夠接近。您可以see the differences in the implementation

int 
thr_join(thread_t tid, thread_t *departed, void **status) 
{ 
    int error = _thrp_join(tid, departed, status, 1); 
    return ((error == EINVAL)? ESRCH : error); 
} 

/* 
* pthread_join() differs from Solaris thr_join(): 
* It does not return the departed thread's id 
* and hence does not have a "departed" argument. 
* It returns EINVAL if tid refers to a detached thread. 
*/ 
#pragma weak _pthread_join = pthread_join 
int 
pthread_join(pthread_t tid, void **status) 
{ 
    return ((tid == 0)? ESRCH : _thrp_join(tid, NULL, status, 1)); 
} 

它們甚至使用相同的內部函數實現。

但是你不想使用Solaris線程。只需使用POSIX線程。