From a3c94d7bfa65c1bed8ce77a65f25c2408c1c2802 Mon Sep 17 00:00:00 2001 From: Gabor Melis Date: Tue, 9 Aug 2005 15:05:46 +0000 Subject: [PATCH] 0.9.3.35: minor thread changes * reverted: thread state synchronization change in gc_start_the_world that did nothing but slowed things down * reverted: set the thread state to dead in C when things are really over not in lisp when more allocation can happen and confuse gc * gc_stop_the_world: yield the cpu when waiting for a thread to suspend --- src/code/target-thread.lisp | 14 -------------- src/runtime/interrupt.c | 3 +-- src/runtime/thread.c | 16 +++++++--------- version.lisp-expr | 2 +- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/code/target-thread.lisp b/src/code/target-thread.lisp index 918422f..81e349e 100644 --- a/src/code/target-thread.lisp +++ b/src/code/target-thread.lisp @@ -50,17 +50,6 @@ in future versions." (#.(sb!vm:fixnumize 2) :suspended) (#.(sb!vm:fixnumize 3) :dead)))) -(defun %set-thread-state (thread state) - (setf (sb!sys:sap-ref-sap (thread-%sap thread) - (* sb!vm::thread-state-slot - sb!vm::n-word-bytes)) - (sb!sys:int-sap - (ecase state - (:starting #.(sb!vm:fixnumize 0)) - (:running #.(sb!vm:fixnumize 1)) - (:suspended #.(sb!vm:fixnumize 2)) - (:dead #.(sb!vm:fixnumize 3)))))) - (defun thread-alive-p (thread) #!+sb-doc "Check if THREAD is running." @@ -506,9 +495,6 @@ returns the thread exits." ;; we're going down, can't handle ;; interrupts sanely anymore (sb!unix::block-blockable-signals))))) - ;; mark the thread dead, so that the gc does not - ;; wait for it to handle sig-stop-for-gc - (%set-thread-state thread :dead) ;; and remove what can be the last reference to ;; the thread object (handle-thread-exit thread) diff --git a/src/runtime/interrupt.c b/src/runtime/interrupt.c index 22e6a76..9a5cb5f 100644 --- a/src/runtime/interrupt.c +++ b/src/runtime/interrupt.c @@ -638,11 +638,10 @@ sig_stop_for_gc_handler(int signal, siginfo_t *info, void *void_context) sigemptyset(&ss); sigaddset(&ss,SIG_STOP_FOR_GC); sigwaitinfo(&ss,0); - if(thread->state!=STATE_SUSPENDED) { + if(thread->state!=STATE_RUNNING) { lose("sig_stop_for_gc_handler: wrong thread state on wakeup: %ld\n", fixnum_value(thread->state)); } - thread->state=STATE_RUNNING; undo_fake_foreign_function_call(context); } diff --git a/src/runtime/thread.c b/src/runtime/thread.c index adeada3..733f8a2 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -107,6 +107,7 @@ int new_thread_trampoline(struct thread *th) { lispobj function; + int result; function = th->unbound_marker; th->unbound_marker = UNBOUND_MARKER_WIDETAG; if(arch_os_thread_init(th)==0) return 1; @@ -115,7 +116,9 @@ new_thread_trampoline(struct thread *th) while(th->os_thread<1) sched_yield(); th->state=STATE_RUNNING; - return funcall0(function); + result = funcall0(function); + th->state=STATE_DEAD; + return result; } #endif /* LISP_FEATURE_SB_THREAD */ @@ -446,6 +449,8 @@ void gc_stop_the_world() if((p==th) || (p->state==STATE_SUSPENDED) || (p->state==STATE_DEAD)) { p=p->next; + } else { + sched_yield(); } } FSHOW_SIGNAL((stderr,"/gc_stop_the_world:end\n")); @@ -468,17 +473,10 @@ void gc_start_the_world() } FSHOW_SIGNAL((stderr, "/gc_start_the_world: resuming %lu\n", p->os_thread)); + p->state=STATE_RUNNING; thread_kill(p->os_thread,SIG_STOP_FOR_GC); } } - /* we must wait for all threads to leave suspended state else we - * risk signal accumulation and lose any meaning of - * thread->state */ - for(p=all_threads;p;) { - if((p==th) || (p->state!=STATE_SUSPENDED)) { - p=p->next; - } - } release_spinlock(&all_threads_lock); FSHOW_SIGNAL((stderr,"/gc_start_the_world:end\n")); } diff --git a/version.lisp-expr b/version.lisp-expr index 7e073fa..42f8fcd 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"0.9.3.34" +"0.9.3.35" -- 1.7.10.4