+
+void thread_exit_handler(int num, siginfo_t *info, void *v_context)
+{ /* called when a child thread exits */
+ pid_t kid;
+ int status;
+
+ while(1) {
+ kid=waitpid(-1,&status,__WALL|WNOHANG);
+ if(kid<=0) break;
+ if(WIFEXITED(status) || WIFSIGNALED(status)) {
+ struct thread *th=find_thread_by_pid(kid);
+ if(th) th->state=STATE_DEAD;
+ }
+ }
+}
+
+