Re: thread group comments

From: Linus Torvalds (
Date: Fri Sep 01 2000 - 20:15:52 EST

On Sat, 2 Sep 2000, Andi Kleen wrote:
> But I guess you don't want the context switch to a thread manager just to
> generate a thread ? (and which is one of the main causes of the bad thread
> creation latency in Linux currently)

No, you don't need that. Here it is again:

        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
                         * 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 ..

and as Uli points out the only thing you need to do is to switch the
stacks around when you do the nasty "switch threads from under the users
feet" thing.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Thu Sep 07 2000 - 21:00:12 EST