pthread_join()如何确定被调用/等待线程终止?

时间:2021-05-04 20:41:48

i am new in Multithreading. in pthread_join() function we put the main thread on wait till the called thread is not terminated. So my question is here how pthread_join() verify that called thread is terminated.

我是多线程的新手。在pthread_join()函数中,我们将主线程放在等待,直到被调用的线程没有终止。因此,我的问题是pthread_join()如何验证被调用的线程被终止。

1 个解决方案

#1


3  

pthread_join is a portable interface around an operating system facility that instructs the OS scheduler to suspend the calling thread until the target thread has communicated that it has completed (either by returning from its entry point function or because pthread_exit has been called). The necessary wrapping logic and state set up by pthread_create. Essentially, you are waiting for a flag to change, but that's all handled for you by the pthreads library.

pthread_join是操作系统设施周围的一个可移植接口,它指示操作系统调度器挂起调用线程,直到目标线程通知它已经完成(通过从其入口点函数返回或者因为调用了pthread_exit)。pthread_create设置的必要的包装逻辑和状态。本质上,您正在等待更改的标志,但这都是由pthreads库为您处理的。

#1


3  

pthread_join is a portable interface around an operating system facility that instructs the OS scheduler to suspend the calling thread until the target thread has communicated that it has completed (either by returning from its entry point function or because pthread_exit has been called). The necessary wrapping logic and state set up by pthread_create. Essentially, you are waiting for a flag to change, but that's all handled for you by the pthreads library.

pthread_join是操作系统设施周围的一个可移植接口,它指示操作系统调度器挂起调用线程,直到目标线程通知它已经完成(通过从其入口点函数返回或者因为调用了pthread_exit)。pthread_create设置的必要的包装逻辑和状态。本质上,您正在等待更改的标志,但这都是由pthreads库为您处理的。