Index: src/libcfa/concurrency/kernel.c
===================================================================
--- src/libcfa/concurrency/kernel.c	(revision 214e8da33e6cb23acc53448d1c57eea90c6f03ae)
+++ src/libcfa/concurrency/kernel.c	(revision ae3bb3d4c4497f3abf9f84e5122b839f05b1dac3)
@@ -17,4 +17,5 @@
 #include <stddef.h>
 #include <errno.h>
+#include <string.h>
 extern "C" {
 #include <stdio.h>
@@ -50,5 +51,7 @@
 thread_desc * mainThread;
 
-struct { __dllist_t(cluster) list; __spinlock_t lock; } global_clusters;
+extern "C" {
+struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;
+}
 
 //-----------------------------------------------------------------------------
@@ -150,8 +153,8 @@
 
 void ^?{}(processor & this) with( this ){
-	if( ! do_terminate ) {
+	if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
 		__cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
 		terminate(&this);
-		verify(this.do_terminate);
+		verify( __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
 		verify( kernelTLS.this_processor != &this);
 		P( terminated );
@@ -199,5 +202,5 @@
 
 		thread_desc * readyThread = NULL;
-		for( unsigned int spin_count = 0; ! this->do_terminate; spin_count++ )
+		for( unsigned int spin_count = 0; ! __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST); spin_count++ )
 		{
 			readyThread = nextThread( this->cltr );
@@ -218,5 +221,6 @@
 			else
 			{
-				spin(this, &spin_count);
+				// spin(this, &spin_count);
+				halt(this);
 			}
 		}
@@ -545,6 +549,6 @@
 	__cfaabi_dbg_print_safe("Kernel : Starting\n");
 
-	global_clusters.list{ __get };
-	global_clusters.lock{};
+	__cfa_dbg_global_clusters.list{ __get };
+	__cfa_dbg_global_clusters.lock{};
 
 	// Initialize the main cluster
@@ -627,6 +631,7 @@
 	// When its coroutine terminates, it return control to the mainThread
 	// which is currently here
-	mainProcessor->do_terminate = true;
+	__atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
 	returnToKernel();
+	mainThread->self_cor.state = Halted;
 
 	// THE SYSTEM IS NOW COMPLETELY STOPPED
@@ -644,6 +649,6 @@
 	^(mainThread){};
 
-	^(global_clusters.list){};
-	^(global_clusters.lock){};
+	^(__cfa_dbg_global_clusters.list){};
+	^(__cfa_dbg_global_clusters.lock){};
 
 	__cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
@@ -655,4 +660,6 @@
 
 void halt(processor * this) with( *this ) {
+	verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
+
 	with( *cltr ) {
 		lock      (proc_list_lock __cfaabi_dbg_ctx2);
@@ -664,7 +671,15 @@
 	__cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
 
-	verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200);
+	// #ifdef __CFA_WITH_VERIFY__
+	// 	int sval = 0;
+	// 	sem_getvalue(&this->idleLock, &sval);
+	// 	verifyf(sval < 200, "Binary semaphore reached value %d : \n", sval);
+	// #endif
+
+	verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
 	int __attribute__((unused)) ret = sem_wait(&idleLock);
-	verify(ret > 0 || errno == EINTR);
+	// verifyf(ret >= 0 || errno == EINTR, "Sem_wait returned %d (errno %d : %s\n", ret, errno, strerror(errno));
+
+	// wait( idleLock );
 
 	__cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
@@ -681,6 +696,13 @@
 	__cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
 	int __attribute__((unused)) ret = sem_post(&this->idleLock);
-	verify(ret > 0 || errno == EINTR);
-	verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200);
+	// verifyf(ret >= 0 || errno == EINTR, "Sem_post returned %d (errno %d : %s\n", ret, errno, strerror(errno));
+
+	// #ifdef __CFA_WITH_VERIFY__
+	// 	int sval = 0;
+	// 	sem_getvalue(&this->idleLock, &sval);
+	// 	verifyf(sval < 200, "Binary semaphore reached value %d\n", sval);
+	// #endif
+
+	// post( this->idleLock );
 }
 
@@ -798,13 +820,13 @@
 // Global Queues
 void doregister( cluster     & cltr ) {
-	lock      ( global_clusters.lock __cfaabi_dbg_ctx2);
-	push_front( global_clusters.list, cltr );
-	unlock    ( global_clusters.lock );
+	lock      ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2);
+	push_front( __cfa_dbg_global_clusters.list, cltr );
+	unlock    ( __cfa_dbg_global_clusters.lock );
 }
 
 void unregister( cluster     & cltr ) {
-	lock  ( global_clusters.lock __cfaabi_dbg_ctx2);
-	remove( global_clusters.list, cltr );
-	unlock( global_clusters.lock );
+	lock  ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2);
+	remove( __cfa_dbg_global_clusters.list, cltr );
+	unlock( __cfa_dbg_global_clusters.lock );
 }
 
