Index: src/libcfa/concurrency/kernel.c
===================================================================
--- src/libcfa/concurrency/kernel.c	(revision 83a071f98d287fe0dd150376b0c6ea5ff812b18b)
+++ src/libcfa/concurrency/kernel.c	(revision c315863ca6b244f425507450d481bda8f139eeee)
@@ -1,3 +1,2 @@
-//                              -*- Mode: CFA -*-
 //
 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
@@ -10,7 +9,7 @@
 // Author           : Thierry Delisle
 // Created On       : Tue Jan 17 12:27:26 2017
-// Last Modified By : Thierry Delisle
-// Last Modified On : --
-// Update Count     : 0
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Fri Jul 21 22:33:18 2017
+// Update Count     : 2
 //
 
@@ -42,14 +41,12 @@
 //-----------------------------------------------------------------------------
 // Kernel storage
-#define KERNEL_STORAGE(T,X) static char X##Storage[sizeof(T)]
-
-KERNEL_STORAGE(processorCtx_t, systemProcessorCtx);
-KERNEL_STORAGE(cluster, systemCluster);
-KERNEL_STORAGE(system_proc_t, systemProcessor);
-KERNEL_STORAGE(thread_desc, mainThread);
+KERNEL_STORAGE(cluster,           mainCluster);
+KERNEL_STORAGE(processor,         mainProcessor);
+KERNEL_STORAGE(processorCtx_t,    mainProcessorCtx);
+KERNEL_STORAGE(thread_desc,       mainThread);
 KERNEL_STORAGE(machine_context_t, mainThreadCtx);
 
-cluster * systemCluster;
-system_proc_t * systemProcessor;
+cluster *     mainCluster;
+processor *   mainProcessor;
 thread_desc * mainThread;
 
@@ -57,7 +54,8 @@
 // Global state
 
-volatile thread_local processor * this_processor;
-volatile thread_local coroutine_desc * this_coroutine;
-volatile thread_local thread_desc * this_thread;
+thread_local coroutine_desc * volatile this_coroutine;
+thread_local thread_desc *    volatile this_thread;
+thread_local processor *      volatile this_processor;
+
 volatile thread_local bool preemption_in_progress = 0;
 volatile thread_local unsigned short disable_preempt_count = 1;
@@ -85,5 +83,5 @@
 
 	this.limit = (void *)(((intptr_t)this.base) - this.size);
-	this.context = &mainThreadCtxStorage;
+	this.context = &storage_mainThreadCtx;
 	this.top = this.base;
 }
@@ -125,5 +123,5 @@
 
 void ?{}(processor & this) {
-	this{ systemCluster };
+	this{ mainCluster };
 }
 
@@ -131,7 +129,6 @@
 	this.cltr = cltr;
 	(this.terminated){ 0 };
-	this.is_terminated = false;
+	this.do_terminate = false;
 	this.preemption_alarm = NULL;
-	this.preemption = default_preemption();
 	this.pending_preemption = false;
 
@@ -142,31 +139,18 @@
 	this.cltr = cltr;
 	(this.terminated){ 0 };
-	this.is_terminated = false;
+	this.do_terminate = false;
 	this.preemption_alarm = NULL;
-	this.preemption = default_preemption();
 	this.pending_preemption = false;
 	this.kernel_thread = pthread_self();
 
 	this.runner = &runner;
-	LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", &runner);
+	LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);
 	runner{ &this };
 }
 
-LIB_DEBUG_DO( bool validate( alarm_list_t * this ); )
-
-void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t & runner) {
-	(this.alarms){};
-	(this.alarm_lock){};
-	this.pending_alarm = false;
-
-	(this.proc){ cltr, runner };
-
-	verify( validate( &this.alarms ) );
-}
-
 void ^?{}(processor & this) {
-	if( ! this.is_terminated ) {
+	if( ! this.do_terminate ) {
 		LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);
-		this.is_terminated = true;
+		this.do_terminate = true;
 		P( &this.terminated );
 		pthread_join( this.kernel_thread, NULL );
@@ -176,5 +160,7 @@
 void ?{}(cluster & this) {
 	( this.ready_queue ){};
-	( this.lock ){};
+	( this.ready_queue_lock ){};
+
+	this.preemption = default_preemption();
 }
 
@@ -199,5 +185,5 @@
 
 		thread_desc * readyThread = NULL;
-		for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ )
+		for( unsigned int spin_count = 0; ! this->do_terminate; spin_count++ )
 		{
 			readyThread = nextThread( this->cltr );
@@ -343,7 +329,7 @@
 	verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
 
-	lock( &systemProcessor->proc.cltr->lock DEBUG_CTX2 );
-	append( &systemProcessor->proc.cltr->ready_queue, thrd );
-	unlock( &systemProcessor->proc.cltr->lock );
+	lock(   &this_processor->cltr->ready_queue_lock DEBUG_CTX2 );
+	append( &this_processor->cltr->ready_queue, thrd );
+	unlock( &this_processor->cltr->ready_queue_lock );
 
 	verify( disable_preempt_count > 0 );
@@ -352,7 +338,7 @@
 thread_desc * nextThread(cluster * this) {
 	verify( disable_preempt_count > 0 );
-	lock( &this->lock DEBUG_CTX2 );
+	lock( &this->ready_queue_lock DEBUG_CTX2 );
 	thread_desc * head = pop_head( &this->ready_queue );
-	unlock( &this->lock );
+	unlock( &this->ready_queue_lock );
 	verify( disable_preempt_count > 0 );
 	return head;
@@ -452,6 +438,6 @@
 	// Start by initializing the main thread
 	// SKULLDUGGERY: the mainThread steals the process main thread
-	// which will then be scheduled by the systemProcessor normally
-	mainThread = (thread_desc *)&mainThreadStorage;
+	// which will then be scheduled by the mainProcessor normally
+	mainThread = (thread_desc *)&storage_mainThread;
 	current_stack_info_t info;
 	(*mainThread){ &info };
@@ -459,32 +445,31 @@
 	LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
 
-	// Initialize the system cluster
-	systemCluster = (cluster *)&systemClusterStorage;
-	(*systemCluster){};
-
-	LIB_DEBUG_PRINT_SAFE("Kernel : System cluster ready\n");
-
-	// Initialize the system processor and the system processor ctx
+	// Initialize the main cluster
+	mainCluster = (cluster *)&storage_mainCluster;
+	(*mainCluster){};
+
+	LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");
+
+	// Initialize the main processor and the main processor ctx
 	// (the coroutine that contains the processing control flow)
-	systemProcessor = (system_proc_t *)&systemProcessorStorage;
-	(*systemProcessor){ systemCluster, *(processorCtx_t *)&systemProcessorCtxStorage };
-
-	// Add the main thread to the ready queue
-	// once resume is called on systemProcessor->runner the mainThread needs to be scheduled like any normal thread
-	ScheduleThread(mainThread);
+	mainProcessor = (processor *)&storage_mainProcessor;
+	(*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
 
 	//initialize the global state variables
-	this_processor = &systemProcessor->proc;
+	this_processor = mainProcessor;
 	this_thread = mainThread;
 	this_coroutine = &mainThread->cor;
-	disable_preempt_count = 1;
 
 	// Enable preemption
 	kernel_start_preemption();
 
-	// SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
+	// Add the main thread to the ready queue
+	// once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
+	ScheduleThread(mainThread);
+
+	// SKULLDUGGERY: Force a context switch to the main processor to set the main thread's context to the current UNIX
 	// context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
 	// mainThread is on the ready queue when this call is made.
-	resume( *systemProcessor->proc.runner );
+	resume( *mainProcessor->runner );
 
 
@@ -501,8 +486,8 @@
 	disable_interrupts();
 
-	// SKULLDUGGERY: Notify the systemProcessor it needs to terminates.
+	// SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
 	// When its coroutine terminates, it return control to the mainThread
 	// which is currently here
-	systemProcessor->proc.is_terminated = true;
+	mainProcessor->do_terminate = true;
 	suspend();
 
@@ -512,8 +497,8 @@
 	kernel_stop_preemption();
 
-	// Destroy the system processor and its context in reverse order of construction
+	// Destroy the main processor and its context in reverse order of construction
 	// These were manually constructed so we need manually destroy them
-	^(*systemProcessor->proc.runner){};
-	^(systemProcessor){};
+	^(*mainProcessor->runner){};
+	^(mainProcessor){};
 
 	// Final step, destroy the main thread since it is no longer needed
@@ -699,4 +684,5 @@
 	return top;
 }
+
 // Local Variables: //
 // mode: c //
