You are not logged in.
Pages: 1
In linux, creating thread is same as process (clone()), except the virtual address space gets shared with the parent.
If a running main process(thread) creates new thread, and if main thread exits, why should the new thread too exit? both are different entities,
The same doesn't happen if the child thread exits, the parent thread would be alive.
Could anyone plz clear this doubt..
Offline
There are two system calls to exit in Linux: _exit and exit_group. The first just
exits the process, and in case of a thread only the thread. The second exits all
threads within the thread group. According to POSIX an exit(3) should exit
all the threads, so that's why glibc calls exit_group then. The same is true for
when main returns. If you don't want that you have to call pthread_exit to exit
the main thread (and probably make the other threads detachable).
Offline
Pages: 1