When you program with POSIX Threads API, there is one thing about pthread_exit() that you may ignore for mistake. In subroutines that complete normally, there is nothing special you have to do unless you want to pass a return code back using pthread_exit(). The completion won't affect the other threads which were created by the main thread of this subroutine. However, in main(), when the code has been executed to the end, there could leave a choice for you. If you want to kill all the threads that main() created before, you can dispense with calling any functions. But if you want to keep the process and all the other threads except for the main thread alive after the exit of main(), then you can call pthread_exit() to realize it. And any files opened inside the main thread will remain open after its termination.
原帖由 yylogo 于 2010-1-2 20:24 发表
额,, 什么主线程, 子线程..
线程都是一样的, 退出了一个不会影响另外一个..
但是你们口中的那个"主线程"吧,, 是main,, 在main执行完之后, 会调用exit()..
exit() 会让进程Over.. 那所有线程不就都GoodbYE了 ...
原帖由 c/unix 于 2010-1-4 10:29 发表
我测试了一下,main线程调用pthread_exit之后,return 0根本没执行,所有进程就没有退出。
#include
#include
void* thrd_start_routine(void* v)
{
int i;
for (i = 0; i < 1 ...
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |