Index: src/examples/thread.c
===================================================================
--- src/examples/thread.c	(revision 4a3386b40a240bd9769a705886c70d008e23008c)
+++ src/examples/thread.c	(revision 8f49a54ffd2ebee0164eb91c530d7625a9d1f910)
@@ -1,67 +1,47 @@
-// #include <kernel>
+#include <fstream>
 #include <stdlib>
 #include <threads>
 
-// // Start coroutine routines
-// extern "C" {
-//       forall(dtype T | is_coroutine(T))
-//       void CtxInvokeCoroutine(T * this);
+// Start coroutine routines
+struct MyThread {
+	thread_h t;
+	unsigned id;
+	unsigned count;
+};
 
-//       forall(dtype T | is_coroutine(T))
-//       void CtxStart(T * this, void ( *invoke)(T *));
+DECL_THREAD(MyThread)
 
-// 	forall(dtype T | is_coroutine(T))
-//       void CtxInvokeThread(T * this);
-// }
+void ?{}( MyThread * this, unsigned id, unsigned count ) {
+	this->id = id;
+	this->count = count;
+}
 
-// struct MyThread {
-// 	thread_h t;
-// 	unsigned id;
-// 	unsigned count;
-// };
+void main(MyThread* this) {
+	sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl;
+	suspend();
 
-// void ?{}( MyThread * this ) {
-// 	this->id = 0;
-// 	this->count = 10;
-// }
+	for(int i = 0; i < this->count; i++) {
+		sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl;
+		suspend();
+	}
+}
 
-// void ?{}( MyThread * this, unsigned id, unsigned count ) {
-// 	this->id = id;
-// 	this->count = count;
-// }
+int main(int argc, char* argv[]) {
 
-// void ^?{}( MyThread * this ) {}
+	unsigned itterations = 10;
+	if(argc == 2) { 
+		int val = ato(argv[1]);
+		assert(val >= 0);
+		itterations = val;
+	}
 
-// void main(MyThread* this) {
-// 	printf("Main called with %p\n", this);
-// 	printf("Thread %d : Suspending %d times\n", this->id, this->count);
+	sout | "User main begin" | endl;
 
-// 	for(int i = 0; i < this->count; i++) {
-// 		printf("Thread %d : Suspend No. %d\n", this->id, i + 1);
-// 		printf("Back to %p\n", &this->t.c);
-// 		suspend();
-// 	}
-// }
+	{
+		thread(MyThread) thread1 = { (unsigned)1, itterations };
+		thread(MyThread) thread2 = { (unsigned)2, itterations };
+	}
 
-// thread_h* get_thread(MyThread* this) {
-// 	return &this->t;
-// }
-
-// coroutine* get_coroutine(MyThread* this) {
-// 	return &this->t.c;
-// }
-
-int main() {
-	printf("Main is %p\n", this_coroutine());
-
-	// thread(MyThread) thread1;
-	// thread(MyThread) thread2;
-
-	// thread2.handle.id = 1;
-
-
-	// // kernel_run();
-
-	// printf("Kernel terminated correctly\n");
+	sout | "User main end" | endl;
 
 	return 0;
Index: src/libcfa/concurrency/coroutines.c
===================================================================
--- src/libcfa/concurrency/coroutines.c	(revision 4a3386b40a240bd9769a705886c70d008e23008c)
+++ src/libcfa/concurrency/coroutines.c	(revision 8f49a54ffd2ebee0164eb91c530d7625a9d1f910)
@@ -100,6 +100,4 @@
 // is not inline (We can't inline Cforall in C)
 void suspend_no_inline(void) {
-	LIB_DEBUG_PRINTF("Suspending back : to %p from %p\n", this_coroutine(), this_coroutine() ? this_coroutine()->last : (void*)-1);
-
 	suspend();
 }
Index: src/libcfa/concurrency/invoke.c
===================================================================
--- src/libcfa/concurrency/invoke.c	(revision 4a3386b40a240bd9769a705886c70d008e23008c)
+++ src/libcfa/concurrency/invoke.c	(revision 8f49a54ffd2ebee0164eb91c530d7625a9d1f910)
@@ -33,4 +33,7 @@
       main( this );
 
+      cor->state = Halt;
+      cor->notHalted = false;
+
       //Final suspend, should never return
       __suspend_no_inline__F___1();
@@ -54,4 +57,6 @@
       main( this );
 
+      cor->state = Halt;
+      cor->notHalted = false;
       __scheduler_remove__F_P9sthread_h__1(thrd);
 
Index: src/libcfa/concurrency/kernel.c
===================================================================
--- src/libcfa/concurrency/kernel.c	(revision 4a3386b40a240bd9769a705886c70d008e23008c)
+++ src/libcfa/concurrency/kernel.c	(revision 8f49a54ffd2ebee0164eb91c530d7625a9d1f910)
@@ -119,9 +119,9 @@
 	// context switch to specified coroutine
 	// Which is now the current_coroutine
-	LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
+	// LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
 	current_coroutine = thrd_ctx;
 	CtxSwitch( proc_ctx->stack.context, thrd_ctx->stack.context );
 	current_coroutine = proc_ctx;
-	LIB_DEBUG_PRINTF("Kernel : returned from ctx %p (to %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
+	// LIB_DEBUG_PRINTF("Kernel : returned from ctx %p (to %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
 
 	// when CtxSwitch returns we are back in the processor coroutine
@@ -136,5 +136,4 @@
 
 void scheduler_add( thread_h * thrd ) {
-	LIB_DEBUG_PRINTF("Kernel : scheduling %p on core %p (%d spots)\n", thrd, systemProcessor, systemProcessor->thread_count);
 	for(int i = 0; i < systemProcessor->thread_count; i++) {
 		if(systemProcessor->threads[i] == NULL) {
@@ -143,22 +142,15 @@
 		}
 	}
-	assert(false);
+	assertf(false, "Scheduler full");
 }
 
 void scheduler_remove( thread_h * thrd ) {
-	LIB_DEBUG_PRINTF("Kernel : unscheduling %p from core %p\n", thrd, systemProcessor);
 	for(int i = 0; i < systemProcessor->thread_count; i++) {
 		if(systemProcessor->threads[i] == thrd) {
 			systemProcessor->threads[i] = NULL;
-			break;
-		}
-	}
-	for(int i = 0; i < systemProcessor->thread_count; i++) {
-		if(systemProcessor->threads[i] != NULL) {
 			return;
 		}
 	}
-	LIB_DEBUG_PRINTF("Kernel : terminating core %p\n", systemProcessor);	
-	systemProcessor->terminated = true;
+	assertf(false, "Trying to unschedule unkown thread");
 }
 
@@ -229,10 +221,10 @@
 
 	mainThread_info_t ctx;
-	LIB_DEBUG_PRINTF("Kernel :    base : %p\n", ctx.base );
-	LIB_DEBUG_PRINTF("Kernel :     top : %p\n", ctx.top );
-	LIB_DEBUG_PRINTF("Kernel :   limit : %p\n", ctx.limit );
-	LIB_DEBUG_PRINTF("Kernel :    size : %x\n", ctx.size );
-	LIB_DEBUG_PRINTF("Kernel : storage : %p\n", ctx.storage );
-	LIB_DEBUG_PRINTF("Kernel : context : %p\n", ctx.context );
+	// LIB_DEBUG_PRINTF("Kernel :    base : %p\n", ctx.base );
+	// LIB_DEBUG_PRINTF("Kernel :     top : %p\n", ctx.top );
+	// LIB_DEBUG_PRINTF("Kernel :   limit : %p\n", ctx.limit );
+	// LIB_DEBUG_PRINTF("Kernel :    size : %x\n", ctx.size );
+	// LIB_DEBUG_PRINTF("Kernel : storage : %p\n", ctx.storage );
+	// LIB_DEBUG_PRINTF("Kernel : context : %p\n", ctx.context );
 
 	// Start by initializing the main thread
@@ -265,8 +257,10 @@
 	scheduler_remove(mainThread);
 
-	LIB_DEBUG_PRINTF("Suspending main\n");
+	LIB_DEBUG_PRINTF("Kernel : Terminating system processor\n");		
+	systemProcessor->terminated = true;
+
 	suspend();
 
-	LIB_DEBUG_PRINTF("Kernel : Control return to initial process thread\n");
+	LIB_DEBUG_PRINTF("Kernel : Control returned to initial process thread\n");
 
 	^(systemProcessor->ctx){};
Index: src/libcfa/concurrency/threads
===================================================================
--- src/libcfa/concurrency/threads	(revision 4a3386b40a240bd9769a705886c70d008e23008c)
+++ src/libcfa/concurrency/threads	(revision 8f49a54ffd2ebee0164eb91c530d7625a9d1f910)
@@ -33,4 +33,6 @@
 	void ^?{}(T*);*/
 };
+
+#define DECL_THREAD(X) static inline thread_h* get_thread(X* this) { return &this->t; } void main(X* this);
 
 forall(otype T | is_thread(T) )
Index: src/libcfa/concurrency/threads.c
===================================================================
--- src/libcfa/concurrency/threads.c	(revision 4a3386b40a240bd9769a705886c70d008e23008c)
+++ src/libcfa/concurrency/threads.c	(revision 8f49a54ffd2ebee0164eb91c530d7625a9d1f910)
@@ -46,5 +46,4 @@
 forall(otype T | is_thread(T) )
 void ?{}( thread(T)* this ) {
-	printf("thread() ctor\n");
 	(&this->handle){};
 	start(this);
@@ -89,5 +88,9 @@
 forall(otype T | is_thread(T) )
 void stop( thread(T)* this ) {
-
+	T* handle  = &this->handle;
+	thread_h*  thrd_h = get_thread   (handle);
+	while( thrd_h->c.notHalted ) {
+		suspend();
+	}
 }
 
