From d350869d104f627ca126c2bdc739355f19697246 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 15 May 2013 09:15:11 -0600 Subject: [PATCH] fix thread-creation problem When starting a thread, the thread was created and partially initialized before trying to get a name for the thread from the given thunk, but getting a name for the thunk could trigger scheduler descisions, which could get confused by the partially initialized thread. --- collects/tests/racket/thread.rktl | 7 +++++++ src/racket/src/thread.c | 17 ++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/collects/tests/racket/thread.rktl b/collects/tests/racket/thread.rktl index e8bf5125b4..151314def1 100644 --- a/collects/tests/racket/thread.rktl +++ b/collects/tests/racket/thread.rktl @@ -1453,6 +1453,13 @@ (lambda () (set! v "yes")))))) (test "yes" values v)) +; -------------------- +;; Make sure that extracting a procedure name for a thread +;; doesn't create trouble: + +(for ([i 1000]) + (thread (make-keyword-procedure (lambda (x y) '())))) + ; -------------------- (report-errs) diff --git a/src/racket/src/thread.c b/src/racket/src/thread.c index 17b32e963d..0ad84580b0 100644 --- a/src/racket/src/thread.c +++ b/src/racket/src/thread.c @@ -2884,6 +2884,7 @@ static Scheme_Object *make_subprocess(Scheme_Object *child_thunk, { Scheme_Thread *child; int turn_on_multi; + Scheme_Object *name_sym = NULL; turn_on_multi = !scheme_first_thread->next; @@ -2897,24 +2898,26 @@ static Scheme_Object *make_subprocess(Scheme_Object *child_thunk, maybe_recycle_cell = NULL; } - child = make_thread(config, cells, break_cell, mgr, child_start); - - /* Use child_thunk name, if any, for the thread name: */ + /* Use child_thunk name, if any, for the thread name. + (Get it before calling make_thread(), in case + getting the name blocks.) */ { - Scheme_Object *sym; const char *s; int len; s = scheme_get_proc_name(child_thunk, &len, -1); if (s) { if (len < 0) - sym = (Scheme_Object *)s; + name_sym = (Scheme_Object *)s; else - sym = scheme_intern_exact_symbol(s, len); - child->name = sym; + name_sym = scheme_intern_exact_symbol(s, len); } } + child = make_thread(config, cells, break_cell, mgr, child_start); + if (name_sym) + child->name = name_sym; + { Scheme_Object *v; v = scheme_thread_cell_get(break_cell, cells);