From 429704a5f67c54fb8e33dab97f917b1914b3eb72 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sat, 27 Dec 2014 14:51:12 +0900 Subject: [PATCH] thread-terminate should set an exception in the thread --- eval.c | 2 ++ include/chibi/sexp.h | 1 + lib/srfi/18/threads.c | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/eval.c b/eval.c index a733038d..448f8122 100644 --- a/eval.c +++ b/eval.c @@ -492,6 +492,8 @@ void sexp_init_eval_context_globals (sexp ctx) { = sexp_user_exception(ctx, SEXP_FALSE, "I/O would block", SEXP_NULL); sexp_global(ctx, SEXP_G_IO_BLOCK_ONCE_ERROR) = sexp_user_exception(ctx, SEXP_FALSE, "I/O would block once", SEXP_NULL); + sexp_global(ctx, SEXP_G_THREAD_TERMINATE_ERROR) + = sexp_user_exception(ctx, SEXP_FALSE, "thread terminated", SEXP_NULL); sexp_global(ctx, SEXP_G_THREADS_FRONT) = SEXP_NULL; sexp_global(ctx, SEXP_G_THREADS_BACK) = SEXP_NULL; sexp_global(ctx, SEXP_G_THREADS_SIGNALS) = SEXP_ZERO; diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 45778bbb..922890ab 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -1235,6 +1235,7 @@ enum sexp_context_globals { #if SEXP_USE_GREEN_THREADS SEXP_G_IO_BLOCK_ERROR, SEXP_G_IO_BLOCK_ONCE_ERROR, + SEXP_G_THREAD_TERMINATE_ERROR, SEXP_G_THREADS_SCHEDULER, SEXP_G_THREADS_FRONT, SEXP_G_THREADS_BACK, diff --git a/lib/srfi/18/threads.c b/lib/srfi/18/threads.c index fbb47d34..1113e12e 100644 --- a/lib/srfi/18/threads.c +++ b/lib/srfi/18/threads.c @@ -138,8 +138,13 @@ static int sexp_delete_list (sexp ctx, int global, sexp x) { sexp sexp_thread_terminate (sexp ctx, sexp self, sexp_sint_t n, sexp thread) { sexp res = sexp_make_boolean(ctx == thread); + sexp_assert_type(ctx, sexp_contextp, SEXP_CONTEXT, thread); /* terminate the thread and all children */ for ( ; thread && sexp_contextp(thread); thread=sexp_context_child(thread)) { + /* if not already terminated set an exception status */ + sexp_context_errorp(thread) = 1; + sexp_context_result(thread) = + sexp_global(ctx, SEXP_G_THREAD_TERMINATE_ERROR); /* zero the refuel - this tells the scheduler the thread is terminated */ sexp_context_refuel(thread) = 0; /* unblock the thread if needed so it can be scheduled and terminated */