Re: kernel thread support - LWP's

Zack Weinberg (zack@rabi.columbia.edu)
Sat, 17 Jul 1999 19:01:30 -0400


On Sat, 17 Jul 1999 22:48:41 +0300 (IDT), Alon Ziv wrote:
>On 16 Jul 1999, Andi Kleen wrote:
>
>> zack@rabi.columbia.edu (Zack Weinberg) writes:
>> >
>> > There's another lovely detail: The "initial thread" (the one that was
>> > executing before the first call to pthread_create) isn't a child of the
>> > manager; it's the parent of. Per POSIX, the manager has to notice when th
>e
>> > initial thread goes away and kill all the others. That's why there is a
>> > getppid in the above. The select times out every two seconds just so it c
>an
>> > check.
>>
>Wouldn't it be better if the initial thread _became_ the manager thread,
>and a new thread was implicitly created as a duplicate of what it was
>doing?
>Sure, it would need some fiddling (e.g., the `old' thread, which now
>becomes the manager, will be the one to get a new stack; the old stack is
>moved to the `new' initial thread). But it would simplify the rest, no?

I thought of that. It would definitely simplify the guts, but I have this
nasty suspicion it would break too many things. For example, imagine that
your program is a daemon which has recorded its pid somewhere so it can be
sent SIGHUP when it needs to reread its config files. It did that before
calling pthread_create. The signal will get sent to the manager, not the
thread that's actually listening.

(Of course, the manager could reflect the signal to a "real" thread. That
_could_ get you closer to POSIX thread semantics. It'd double signal
latency and serialize, but correctness is more important than speed...)

>> This sounds reasonable. CLONE_WAIT ? Shouldn't be that hard to implement.
>>
>
>This will probably solve this part of the problem beautifully.
>
>I remember someone (David Wragg <dpw@doc.ic.ac.uk>) once mentioned another
>new flag idea: a CLONE_SIBLING flag, which will mean that if the new
>thread does a clone() the new thread will get the same ppid of the parent.
>This (together with the redefinition of the manager thread, above) will
>mean that all of the threads report directly to the manager, and any
>thread may create another thread _without_ communicating to the manager
>(it just creates a new sibling).

I like it.

>Ehh... What about just doing something similar to the daemon start-up
>code--- a la if (clone(...)) exit(0); ?? (Of course, while taking care to
>cheat well enough that the thread won't notice it's actually a new kernel
>task...)

Would work for initially detached threads (with more overhead), but you can
detach a thread at any point after its creation.

It occurs to me that the library has to do cleanup when a thread exits. It
could be done by the exiting thread _if_ we are prepared to live with the
cleanup not happening when a thread gets kill -9.

zw

p.s. Someone is theoretically rewriting libpthread. It doesn't look likely
to get done anytime soon though.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/