DragonFly BSD
DragonFly kernel List (threaded) for 2005-09
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: libthread_xu pthread_exit() behaviour

To: Simon 'corecode' Schubert <corecode@xxxxxxxxxxxx>
From: David Xu <bsddiy@xxxxxxx>
Date: Sun, 25 Sep 2005 08:58:23 +0800

Simon 'corecode' Schubert wrote:

at the moment I'm looking at the threading stuff and I found some issues:

If the main() thread pthread_exit()s, the "process" visible to the parent will exit. This is because the kernel doesn't have the notion of "threads" and "processes": The pid of the "process" goes away and thus all other threads become background processes (threads).

I am not sure where this is handled best. Maybe in kernel when dealing with p->p_peers (see next point):

If the main() thread exit()s, it won't tear down all other threads. This is an easy fix: just use RFTHREAD in the rfork_thread() and this works as expected. On the other hand if the main thread pthread_exit()s (see above) it will kill all other threads as well.

If we want the kernel to keep thread leaders around (sleeping?) until all peers have been pthread_exit()ed, we need a way for the userland to signal to the kernel that the thread is actually pthread_exit()ing and not trying to tear down all threads with exit() [new syscall?]

Am I missing something? Comments welcome!


If any thread calls exit(), all other threads will be killed by kernel, I think there should be a syscall to only exit current thread. The main thread should be given the exit code by the thread calling exit(), the race multiple threads calling exit() has to be resolved, execv() has same problem, the main thread has to be kept. if main thread calls pthread_exit(), it should stay in userland or kernel, but howto interact with debugger will complicate things a bit. Another thing is POSIX behavior signal handling, a thread got a STOP signal should be suspend all threads, a SIGCONT has to resume all threads, the main thread shouldn't report SIGCHLD to parent until all others threads are suspended, there might have other trickies, a signal sent to main thread should dispatch the signal to another threads which is not masking it, there should have another syscall to only send a signal to a thread, this is for pthread_kill(). I am just slowly working in it.

David Xu

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]