Index: src/examples/thread.c
===================================================================
--- src/examples/thread.c	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
+++ src/examples/thread.c	(revision c49bf5465f82b0c5b63b5ce37d376ccc54de7b56)
@@ -0,0 +1,66 @@
+#include <kernel>
+#include <stdlib>
+#include <threads>
+
+// Start coroutine routines
+extern "C" {
+      forall(dtype T | is_coroutine(T))
+      void CtxInvokeCoroutine(T * this);
+
+      forall(dtype T | is_coroutine(T))
+      void CtxStart(T * this, void ( *invoke)(T *));
+
+	forall(dtype T | is_coroutine(T))
+      void CtxInvokeThread(T * this);
+}
+
+struct MyThread {
+	thread_h t;
+	int value;
+};
+
+void ?{}( MyThread * this, int value ) {
+	this->value = value;
+}
+
+void ^?{}( MyThread * this ) {}
+
+void co_main(MyThread* this) {
+	printf("Main called with %p\n", this);
+	printf("Thread value is %d\n", this->value);
+}
+
+thread_h* get_thread(MyThread* this) {
+	return &this->t;
+}
+
+coroutine* get_coroutine(MyThread* this) {
+	return &this->t.c;
+}
+
+void ?{}( MyThread * this ) {
+	this->value = 1;
+	printf("MyThread created\n");
+	printf("Address %p\n", this);
+	printf("handle %p\n", get_thread(this));
+	printf("main %p\n", co_main);
+	printf("get_t %p\n", get_thread);
+	printf("invoke %p\n", CtxInvokeThread);
+}
+
+int main() {
+
+	printf("Main is %p\n", this_coroutine());
+
+	printf("Creating thread\n");
+
+	thread(MyThread) thread1;
+
+	printf("Main is %p\n", this_coroutine());	
+
+	printf("First thread created\n");
+
+	kernel_run();
+
+	return 0;
+}
