On Thu, 24 Aug 2000, Andi Kleen wrote:
> >
> > Right: so clone with the PARENT flag set. What's the problem?
>
> Then your original parent would see any thread deaths. Probably not
> what you wanted.
No, it's exactly what you want.
What you do is that the _master_ thread starts out with just CLONE_PID,
but any subsequent thread uses CLONE_PID | CLONE_PARENT.
And no, obviously a pthreads application doesn't even realize anything
like this is going on. What the code would look like is something like
int pthread_create()
{
static int has_done_this_before = 0;
pid_t newtid;
if (!has_done_this_before) {
pid_t tid;
has_done_this_before = 1;
tid = clone(CLONE_PID);
if (tid > 0) {
/*
* original thread becomes hidden master
* thread, and never returns
*/
i_am_the_master_thread();
exit(0);
}
/*
* initial CLONE_PID thread comes here,
* it is now one of the "regular children".
*/
}
newtid = clone(CLONE_PID | CLONE_PARENT);
.. now we have the two "pthread" threads here ..
}
See? (And no, the above is not the syntax for clone(), it's just meant to
kind of show what the intent is).
Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Thu Aug 31 2000 - 21:00:14 EST