This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: CLONE_THREAD
On Thu, May 28, 2009 at 04:30:01AM -0400, Carlos O'Donell wrote:
> On Wed, May 27, 2009 at 2:47 PM, Borislav Trifonov
> <b.trifonov@crissyfieldmedia.com> wrote:
> > Please redirect me if this is the wrong place to ask. I ask here since
> > people that wrote pthreads should certainly be able to answer this.
>
> This mailing list is always the right place to ask any questions even
> remotely related to glibc, it is equivalent to the gcc-help mailing
> list.
However, clone() isn't really a glibc service but rather a direct
wrapper for a kernel syscall.
> > I read in the documentation of clone() that "When a CLONE_THREAD thread
> > terminates, the thread that created it using clone() is not sent a SIGCHLD
> > (or other termination) signal; nor can the status of such a thread be
> > obtained using wait(2)."
> > When I create CLONE_THREAD threads, I noticed that the first thread to exit
> > causes the whole thread group to exit. I'm wondering how I can exit
> > individual threads while allowing others to continue.
>
> Do you have a testcase for this? Which architecture are you targetting?
>
> My expectation would have been that any thread that exits (either
> directly or indirectly via a return from their entry function) is
> detached and does not effect the rest of the threads in the process
> group. However, the clone function (sys_clone syscall) accepts a wide
> variety of clone flags, but in practice only a certain set of flags
> setup a useful userspace process and threads. Which flags are you
> passing to clone? Are you working on your own threading
> implementation?
glibc's exit() calls exit_group() syscall, terminating the whole thread
group. To terminate individual threads, you need to tgkill() them, or
directly call the sys_exit() syscall (but I don't know if glibc provides
any direct interface for it outside of NPTL nowadays).
--
Petr "Pasky" Baudis
The lyf so short, the craft so long to lerne. -- Chaucer