Index: src/libcfa/concurrency/coroutines
===================================================================
--- src/libcfa/concurrency/coroutines	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/coroutines	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -1,3 +1,3 @@
-//                              -*- Mode: CFA -*-
+//                              - *- Mode: CFA - *-
 //
 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
@@ -18,5 +18,5 @@
 #define COROUTINES_H
 
-#include "assert"       //
+#include "assert"
 #include "invoke.h"
 
@@ -26,14 +26,14 @@
 // Anything that is resumed is a coroutine.
 trait is_coroutine(dtype T) {
-      void co_main(T* this);
-      coroutine* get_coroutine(T* this);
+      void co_main(T * this);
+      coroutine * get_coroutine(T * this);
 };
 
 //-----------------------------------------------------------------------------
 // Ctors and dtors
-void ?{}(coStack_t* this);
-void ?{}(coroutine* this);
-void ^?{}(coStack_t* this);
-void ^?{}(coroutine* this);
+void ?{}(coStack_t * this);
+void ?{}(coroutine * this);
+void ^?{}(coStack_t * this);
+void ^?{}(coroutine * this);
 
 //-----------------------------------------------------------------------------
@@ -42,8 +42,8 @@
 
 forall(dtype T | is_coroutine(T))
-static inline void resume(T* cor);
+static inline void resume(T * cor);
 
 forall(dtype T | is_coroutine(T))
-void prime(T* cor);
+void prime(T * cor);
 
 //-----------------------------------------------------------------------------
@@ -53,23 +53,23 @@
 extern "C" {
       forall(dtype T | is_coroutine(T))
-      void CtxInvokeCoroutine(T* this);
+      void CtxInvokeCoroutine(T * this);
 
       forall(dtype T | is_coroutine(T))
-      void CtxStart(T* this, void (*invoke)(T*));
+      void CtxStart(T * this, void ( *invoke)(T *));
 }
 
 // Get current coroutine
-extern coroutine* current_coroutine; //PRIVATE, never use directly
-static inline coroutine* this_coroutine(void) {
+extern coroutine * current_coroutine; //PRIVATE, never use directly
+static inline coroutine * this_coroutine(void) {
 	return current_coroutine;
 }
 
 // Private wrappers for context switch and stack creation
-extern void corCxtSw(coroutine* src, coroutine* dst);
-extern void create_stack( coStack_t* this, unsigned int storageSize );
+extern void corCxtSw(coroutine * src, coroutine * dst);
+extern void create_stack( coStack_t * this, unsigned int storageSize );
 
 // Suspend implementation inlined for performance
 static inline void suspend() {
-      coroutine* src = this_coroutine();		// optimization
+      coroutine * src = this_coroutine();		// optimization
 
 	assertf( src->last != 0,
@@ -87,7 +87,7 @@
 // Resume implementation inlined for performance
 forall(dtype T | is_coroutine(T))
-static inline void resume(T* cor) {
-	coroutine* src = this_coroutine();		// optimization
-	coroutine* dst = get_coroutine(cor);
+static inline void resume(T * cor) {
+	coroutine * src = this_coroutine();		// optimization
+	coroutine * dst = get_coroutine(cor);
 
       if( unlikely(!dst->stack.base) ) {
Index: src/libcfa/concurrency/coroutines.c
===================================================================
--- src/libcfa/concurrency/coroutines.c	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/coroutines.c	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -111,4 +111,6 @@
 // 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 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/invoke.c	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -20,5 +20,5 @@
       void *this
 ) {
-      LIB_DEBUG_PRINTF("Invoke : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
+      LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
 
       struct coroutine* cor = get_coroutine( this );
@@ -31,4 +31,28 @@
 
       main( this );
+
+      //Final suspend, should never return
+      __suspend_no_inline__F___1();
+      assertf(false, "Resumed dead coroutine");
+}
+
+void CtxInvokeThread(
+      void (*main)(void *), 
+      struct thread_h *(*get_thread)(void *), 
+      void *this
+) {
+      LIB_DEBUG_PRINTF("Invoke Thread : Received %p (main %p, get_t %p)\n", this, main, get_thread);
+
+      __suspend_no_inline__F___1();
+
+      struct coroutine* cor = &get_thread( this )->c;
+      cor->state = Active;
+
+      LIB_DEBUG_PRINTF("Invoke Thread : invoking main %p (args %p)\n", main, this);
+      main( this );
+
+      //Final suspend, should never return
+      __suspend_no_inline__F___1();
+      assertf(false, "Resumed dead thread");
 }
 
@@ -40,5 +64,5 @@
       void (*invoke)(void *)
 ) {
-      LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p, get_c %p) to %p\n", this, main, get_coroutine, invoke);
+      LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p) to invoke (%p) from start (%p)\n", this, main, invoke, CtxStart);
 
       struct coStack_t* stack = &get_coroutine( this )->stack;
Index: src/libcfa/concurrency/invoke.h
===================================================================
--- src/libcfa/concurrency/invoke.h	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/invoke.h	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -35,4 +35,8 @@
       };
 
+      struct thread_h {
+            struct coroutine c;
+      };
+
 #endif //_INVOKE_H_
 #else //! defined(__CFA_INVOKE_PRIVATE__)
Index: src/libcfa/concurrency/kernel
===================================================================
--- src/libcfa/concurrency/kernel	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/kernel	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -0,0 +1,29 @@
+//                              -*- Mode: CFA -*-
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// threads --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Jan 17 12:27:26 2016
+// Last Modified By : Thierry Delisle
+// Last Modified On : --
+// Update Count     : 0
+//
+
+#ifndef KERNEL_H
+#define KERNEL_H
+
+extern struct thread_h * the_thread;
+
+void kernel_run( void );
+
+#endif //KERNEL_H
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: src/libcfa/concurrency/kernel.c
===================================================================
--- src/libcfa/concurrency/kernel.c	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/kernel.c	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -0,0 +1,57 @@
+//                              -*- Mode: CFA -*-
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// kernel.c --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Jan 17 12:27:26 2016
+// Last Modified By : Thierry Delisle
+// Last Modified On : --
+// Update Count     : 0
+//
+
+//Header
+#include "kernel"
+
+//C Includes
+#include <stdbool.h>
+
+//CFA Includes
+#include "libhdr.h"
+#include "threads"
+
+//Private includes
+#define __CFA_INVOKE_PRIVATE__
+#include "invoke.h"
+
+thread_h * the_thread = 0;
+
+void kernel_run( void ) {
+	
+	bool done = true;
+	coroutine* processor_cor = this_coroutine();
+	LIB_DEBUG_PRINTF("Kernel : processor cor is %p\n", processor_cor);
+
+	do {
+		thread_h * dst = the_thread;
+
+		LIB_DEBUG_PRINTF("Kernel : picked thread %p\n", dst);
+
+		// set new coroutine that task is executing
+		current_coroutine = &dst->c;
+
+		// context switch to specified coroutine
+		LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p)\n", current_coroutine, processor_cor);
+		CtxSwitch( processor_cor->stack.context, current_coroutine->stack.context );
+		// when CtxSwitch returns we are back in the processor coroutine
+	} while( ! done );
+}
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: src/libcfa/concurrency/threads
===================================================================
--- src/libcfa/concurrency/threads	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/threads	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -18,5 +18,49 @@
 #define THREADS_H
 
+#include "assert"
+#include "invoke.h"
 
+#include "coroutines"
+
+//-----------------------------------------------------------------------------
+// Coroutine trait
+// Anything that implements this trait can be resumed.
+// Anything that is resumed is a coroutine.
+trait is_thread(dtype T /*| sized(T)*/) {
+      void co_main(T* this);
+      thread_h* get_thread(T* this);
+	/*void ?{}(T*);
+	void ^?{}(T*);*/
+};
+
+forall(otype T | is_thread(T) )
+static inline coroutine* get_coroutine(T* this) {
+	return &get_thread(this)->c;
+}
+
+//-----------------------------------------------------------------------------
+// Ctors and dtors
+void ?{}(thread_h* this);
+void ^?{}(thread_h* this);
+
+//-----------------------------------------------------------------------------
+// thread runner
+// Structure that actually start and stop threads
+forall(otype T | is_thread(T) )
+struct thread {
+	T handle;
+};
+
+forall(otype T | is_thread(T) )
+void ?{}( thread(T)* this );
+
+forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
+void ?{}( thread(T)* this, P params );
+
+forall(otype T | is_thread(T) )
+void ^?{}( thread(T)* this );
+
+//-----------------------------------------------------------------------------
+// PRIVATE exposed because of inline
 
 #endif //THREADS_H
Index: src/libcfa/concurrency/threads.c
===================================================================
--- src/libcfa/concurrency/threads.c	(revision 6a3d2e7f051b0a830ce5f421976d81987675c0fa)
+++ src/libcfa/concurrency/threads.c	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -6,5 +6,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// threads --
+// threads.c --
 //
 // Author           : Thierry Delisle
@@ -15,5 +15,80 @@
 //
 
+#include "threads"
 
+#include "kernel"
+#include "libhdr.h"
+
+#define __CFA_INVOKE_PRIVATE__
+#include "invoke.h"
+
+#include <stdlib>
+
+//-----------------------------------------------------------------------------
+// Forward declarations
+forall(otype T | is_thread(T) )
+void start( thread(T)* this );
+
+forall(otype T | is_thread(T) )
+void stop( thread(T)* this );
+
+//-----------------------------------------------------------------------------
+// Thread ctors and dtors
+
+void ?{}(thread_h* this) {
+	(&this->c){};
+}
+
+void ^?{}(thread_h* this) {
+	^(&this->c){};
+}
+
+forall(otype T | is_thread(T) )
+void ?{}( thread(T)* this ) {
+	printf("thread() ctor\n");
+	(&this->handle){};
+	start(this);
+}
+
+forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
+void ?{}( thread(T)* this, P params ) {
+	(&this->handle){ params };
+	start(this);
+}
+
+forall(otype T | is_thread(T) )
+void ^?{}( thread(T)* this ) {
+	stop(this);
+	^(&this->handle){};
+}
+
+//-----------------------------------------------------------------------------
+// Starting and stopping threads
+extern "C" {
+      forall(dtype T | is_thread(T))
+      void CtxInvokeThread(T * this);
+}
+
+forall(otype T | is_thread(T))
+void start( thread(T)* this ) {
+	T* handle  = &this->handle;
+	coroutine* thrd_c = get_coroutine(handle);
+	thread_h*  thrd_h = get_thread   (handle);
+	thrd_c->last = this_coroutine();
+	current_coroutine = thrd_c;
+
+	LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", handle, thrd_c, thrd_h);
+
+	create_stack(&thrd_c->stack, thrd_c->stack.size);
+	CtxStart(handle, CtxInvokeThread);
+	CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
+
+	the_thread = thrd_h;
+}
+
+forall(otype T | is_thread(T) )
+void stop( thread(T)* this ) {
+
+}
 
 // Local Variables: //
