Index: src/libcfa/concurrency/preemption.c
===================================================================
--- src/libcfa/concurrency/preemption.c	(revision 381fdee5d28e58b7c6f73f40e6d72ec1f6dfc7d1)
+++ src/libcfa/concurrency/preemption.c	(revision 43c6dc82effb73435b21d5d267b612e338145e42)
@@ -10,6 +10,6 @@
 // Created On       : Mon Jun 5 14:20:42 2017
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Feb  9 14:42:34 2018
-// Update Count     : 25
+// Last Modified On : Fri Feb  9 16:38:13 2018
+// Update Count     : 14
 //
 
@@ -67,4 +67,9 @@
 }
 
+enum {
+	PREEMPT_NORMAL    = 0,
+	PREEMPT_TERMINATE = 1,
+};
+
 //=============================================================================================
 // Kernel Preemption logic
@@ -192,5 +197,5 @@
 
 	if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
-	    abortf( "internal error, pthread_sigmask" );
+	    abort( "internal error, pthread_sigmask" );
 	}
 }
@@ -203,5 +208,5 @@
 
 	if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
-	    abortf( "internal error, pthread_sigmask" );
+	    abort( "internal error, pthread_sigmask" );
 	}
 }
@@ -209,5 +214,13 @@
 // kill wrapper : signal a processor
 static void preempt( processor * this ) {
-	pthread_kill( this->kernel_thread, SIGUSR1 );
+	sigval_t value = { PREEMPT_NORMAL };
+	pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
+}
+
+// kill wrapper : signal a processor
+void terminate(processor * this) {
+	this->do_terminate = true;
+	sigval_t value = { PREEMPT_TERMINATE };
+	pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
 }
 
@@ -234,5 +247,5 @@
 // Called from kernel_startup
 void kernel_start_preemption() {
-	__cfaabi_dbg_print_safe("Kernel : Starting preemption\n");
+	__cfaabi_dbg_print_safe( "Kernel : Starting preemption\n" );
 
 	// Start with preemption disabled until ready
@@ -255,5 +268,5 @@
 // Called from kernel_shutdown
 void kernel_stop_preemption() {
-	__cfaabi_dbg_print_safe("Kernel : Preemption stopping\n");
+	__cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n" );
 
 	// Block all signals since we are already shutting down
@@ -271,5 +284,5 @@
 	// Preemption is now fully stopped
 
-	__cfaabi_dbg_print_safe("Kernel : Preemption stopped\n");
+	__cfaabi_dbg_print_safe( "Kernel : Preemption stopped\n" );
 }
 
@@ -299,8 +312,21 @@
 	__cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.CFA_REG_IP); )
 
+	// SKULLDUGGERY: if a thread creates a processor and the immediately deletes it,
+	// the interrupt that is supposed to force the kernel thread to preempt might arrive
+	// before the kernel thread has even started running. When that happens an iterrupt
+	// we a null 'this_processor' will be caught, just ignore it.
+	if(!this_processor) return;
+
+	choose(sfp->si_value.sival_int) {
+		case PREEMPT_NORMAL   : ;// Normal case, nothing to do here
+		case PREEMPT_TERMINATE: verify(this_processor->do_terminate);
+		default:
+			abort( "internal error, signal value is %d", sfp->si_value.sival_int );
+	}
+
 	// Check if it is safe to preempt here
 	if( !preemption_ready() ) { return; }
 
-	__cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
+	__cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
 
 	preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
@@ -322,5 +348,5 @@
 
 	if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
-	    abortf( "internal error, pthread_sigmask" );
+	    abort( "internal error, pthread_sigmask" );
 	}
 
@@ -339,7 +365,7 @@
 					continue;
        			case EINVAL :
-				 	abortf("Timeout was invalid.");
+				 	abort( "Timeout was invalid." );
 				default:
-				 	abortf("Unhandled error %d", err);
+				 	abort( "Unhandled error %d", err);
 			}
 		}
@@ -348,5 +374,5 @@
 		assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int);
 
-		// __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
+		// __cfaabi_dbg_print_safe( "Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
 		// Switch on the code (a.k.a. the sender) to
 		switch( info.si_code )
@@ -356,5 +382,5 @@
 		case SI_TIMER:
 		case SI_KERNEL:
-			// __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n");
+			// __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n" );
 			lock( event_kernel->lock __cfaabi_dbg_ctx2 );
 			tick_preemption();
@@ -370,5 +396,5 @@
 
 EXIT:
-	__cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n");
+	__cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
 	return NULL;
 }
