Index: doc/proposals/virtual.txt
===================================================================
--- doc/proposals/virtual.txt	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ doc/proposals/virtual.txt	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -1,3 +1,11 @@
 Proposal for virtual functionality
+
+There are two types of virtual inheritance in this proposal, relaxed
+(implicit) and strict (explicit). Relaxed is the simpler case that uses the
+existing trait system with the addition of trait references and vtables.
+Strict adds some constraints and requires some additional notation but allows
+for down-casting.
+
+Relaxed Virtual Inheritance:
 
 Imagine the following code :
@@ -20,6 +28,6 @@
 void draw(line*);
 
-While all the members of this simple UI support drawing creating a UI that easily
-supports both these UI requires some tedious boiler-plate code :
+While all the members of this simple UI support drawing, creating a UI that
+easily supports both these UI requires some tedious boiler-plate code:
 
 enum type_t { text, line };
@@ -41,31 +49,31 @@
 }
 
-While this code will work as indented, adding any new widgets or any new widget behaviors
-requires changing existing code to add the desired functionality. To ease this maintenance
-effort required CFA introduces the concept of dynamic types, in a manner similar to C++.
-
-A simple usage of dynamic type with the previous example would look like :
-
-drawable* objects[10];
+While this code will work as implemented, adding any new widgets or any new
+widget behaviors requires changing existing code to add the desired
+functionality. To ease this maintenance effort required CFA introduces the
+concept of trait references.
+
+Using trait references to implement the above gives the following :
+
+trait drawable objects[10];
 fill_objects(objects);
 
 while(running) {
-      for(drawable* object : objects) {
+      for(drawable object : objects) {
             draw(object);
       }
 }
 
-However, this is not currently do-able in the current CFA and furthermore is not
-possible to implement statically. Therefore we need to add a new feature to handle
-having dynamic types like this (That is types that are found dynamically not types
-that change dynamically).
-
-C++ uses inheritance and virtual functions to find the
-desired type dynamically. CFA takes inspiration from this solution.
-
-What we really want to do is express the fact that calling draw() on a object
-should find the dynamic type of the parameter before calling the routine, much like the
-hand written example given above. We can express this by adding the virtual keyword on
-the parameter of the constraints on our trait:
+The keyword trait is optional (by the same rules as the struct keyword). This
+is not currently supported in CFA and the lookup is not possible to implement
+statically. Therefore we need to add a new feature to handle having dynamic
+lookups like this.
+
+What we really want to do is express the fact that calling draw() on a trait
+reference should find the underlying type of the given parameter and find how
+it implements the routine, as in the example with the enumeration and union.
+
+For instance specifying that the drawable trait reference looks up the type
+of the first argument to find the implementation would be :
 
 trait drawable(otype T) {
@@ -73,91 +81,197 @@
 };
 
-This expresses the idea that drawable is similar to an abstract base class in C++ and
-also gives meaning to trying to take a pointer of drawable. That is anything that can
-be cast to a drawable pointer has the necessary information to call the draw routine on
-that type. Before that drawable was only a abstract type while now it also points to a
-piece of storage which specify which behavior the object will have at run time.
-
-This storage needs to be allocate somewhere. C++ just adds an invisible pointer at
-the beginning of the struct but we can do something more explicit for users, actually
-have a visible special field :
-
-struct text {
-      char* text;
-      vtable drawable;
-};
-
-struct line{
-      vtable drawable;
-      vec2 start;
-      vec2 end;
-};
-
-With these semantics, adding a "vtable drawable" means that text pointers and line pointers are now
-convertible to drawable pointers. This conversion will not necessarily be a type only change however, indeed,
-the drawable pointer will point to the field "vtable drawable" not the head of the struct. However, since all
-the types are known at compile time, converting pointers becomes a simple offset operations.
-
-The vtable field contains a pointer to a vtable which contains all the information needed for the caller
-to find the function pointer of the desired behavior.
-
-One of the limitations of this design is that it does not support double dispatching, which
-concretely means traits cannot have routines with more than one virtual parameter. This design
-would have many ambiguities if it did support multiple virtual parameter. A futher limitation is 
-that traits over more than one type cannot have vtables meaningfully defined for them, as the 
-particular vtable to use would be a function of the other type(s) the trait is defined over.
-
-It is worth noting that the function pointers in these vtables are bound at object construction, rather than 
-function call-site, as in Cforall's existing polymorphic functions. As such, it is possible that two objects 
-with the same static type would have a different vtable (consider what happens if draw(line*) is overridden 
-between the definitions of two line objects). Given that the virtual drawable* erases static types though, 
-this should not be confusing in practice. A more distressing possibility is that of creating an object that 
-outlives the scope of one of the functions in its vtable. This is certainly a possible bug, but it is of a 
-type that C programmers are familiar with, and should be able to avoid by the usual methods.
-
-Extensibility.
-
-One of the obvious critics of this implementation is that it lacks extensibility for classes
-that cannot be modified (ex: Linux C headers). However this solution can be extended to
-allow more extensibility by adding "Fat pointers".
-
-Indeed, users could already "solve" this issue by writing their own fat pointers as such:
-
-trait MyContext(otype T) {
-      void* get_stack(virtual T*)
-};
-
-void* get_stack(ucontext_t *context);
-
-struct fat_ucontext_t {
-      vtable MyContext;
-      ucontext_t *context;
-}
-
-//Tedious forwarding routine
-void* get_stack(fat_ucontext_t *ptr) {
-      return get_stack(ptr->context);
-}
-
-However, users would have to write all the virtual methods they want to override and make
-them all simply forward to the existing method that takes the corresponding POCO(Plain Old C Object).
-
-The alternative we propose is to use language level fat pointers :
-
-trait MyContext(otype T) {
-      void* get_stack(virtual T*)
-};
-
-void* get_stack(ucontext_t *context);
-
-//The type vptr(ucontext_t) all
-vptr(ucontext_t) context;
-
-These behave exactly as the previous example but all the forwarding routines are automatically generated.
-
-Bikeshedding.
-
-It may be desirable to add fewer new keywords than discussed in this proposal; it is possible that "virtual" 
-could replace both "vtable" and "vptr" above with unambiguous contextual meaning. However, for purposes of 
-clarity in the design discussion it is beneficial to keep the keywords for separate concepts distinct.
-
+This could be implied in simple cases like this one (single parameter on the
+trait and single generic parameter on the function). In more complex cases it
+would have to be explicitly given, or a strong convention would have to be
+enforced (e.g. implementation of trait functions is always drawn from the
+first polymorphic parameter).
+
+Once a function in a trait has been marked as virtual it defines a new
+function that takes in that trait's reference and then dynamically calls the
+underlying type implementation. Hence a trait reference becomes a kind of
+abstract type, cannot be directly instantiated but can still be used.
+
+One of the limitations of this design is that it does not support double
+dispatching, which concretely means traits cannot have routines with more than
+one virtual parameter. The program must have a single table to look up the
+function on. Using trait references with traits with more than one parameter
+is also restricted, initially forbidden, see extension.
+
+Extension: Multi-parameter Virtual Traits:
+
+This implementation can be extended to traits with multiple parameters if
+one is called out as being the virtual trait. For example :
+
+trait iterator(otype T, dtype Item) {
+	Maybe(Item) next(virtual T *);
+}
+
+iterator(int) generators[10];
+
+Which creates a collection of iterators that produce integers, regardless of
+how those iterators are implemented. This may require a note that this trait
+is virtual on T and not Item, but noting it on the functions may be enough.
+
+
+Strict Virtual Inheritance:
+
+One powerful feature relaxed virtual does not support is the idea of down
+casting. Once something has been converted into a trait reference there is
+very little we can do to recover and of the type information, only the trait's
+required function implementations are kept.
+
+To allow down casting strict virtual requires that all traits and structures
+involved be organized into a tree. Each trait or struct must have a unique
+position on this tree (no multiple inheritance).
+
+This is declared as follows :
+
+trait error(otype T) virtual {
+	const char * msg(T *);
+}
+
+trait io_error(otype T) virtual error {
+	FILE * src(T *);
+}
+
+struct eof_error virtual io_error {
+	FILE * fd;
+};
+
+So the trait error is the head of a new tree and io_error is a child of it.
+
+Also the parent trait is implicitly part of the assertions of the children,
+so all children implement the same operations as the parent. By the unique
+path down the tree, we can also uniquely order them so that a prefix of a
+child's vtable has the same format as its parent's.
+
+This gives us an important extra feature, runtime checking of the parent-child
+relationship with a C++ dynamic_cast like operation. Allowing checked
+conversions from trait references to more particular references, which works
+if the underlying type is, or is a child of, the new trait type.
+
+Extension: Multiple Parents
+
+Although each trait/struct must have a unique position on each tree, it could
+have positions on multiple trees. All this requires is the ability to give
+multiple parents, as here :
+
+trait region(otype T) virtual drawable, collider;
+
+The restriction being, the parents must come from different trees. This
+object (and all of its children) can be cast to either tree. This is handled
+by generating a separate vtable for each tree the structure is in.
+
+Extension: Multi-parameter Strict Virtual
+
+If a trait has multiple parameters then one must be called out to be the one
+we generate separate vtables for, as in :
+
+trait example(otype T, otype U) virtual(T) ...
+
+This can generate a separate vtable for each U for which all the T+U
+implementations are provided. These are then separate nodes in the tree (or
+the root of different trees) as if each was created individually. Providing a
+single unique instance of these nodes would be the most difficult aspect of
+this extension, possibly intractable, though with sufficient hoisting and
+link-once duplication it may be possible.
+
+Example:
+
+trait argument(otype T) virtual {
+	char short_name(virtual T *);
+	bool is_set(virtual T *);
+};
+
+trait value_argument(otype T, otype U) virtual(T) argument {
+	U get_value(virtual T *);
+};
+
+Extension: Structural Inheritance
+
+Currently traits must be the internal nodes and structs the leaf nodes.
+Structs could be made internal nodes as well, in which case the child structs
+would likely structurally inherit the fields of their parents.
+
+
+Storing the Virtual Lookup Table (vtable):
+
+We have so far been silent on how the vtable is created, stored and accessed.
+
+Creation happens at compile time. Function pointers are found by using the
+same best match rules as elsewhere (additional rules for defaults from the
+parent may or may not be required). For strict virtual this must happen at the
+global scope and forbidding static functions, to ensure that a single unique
+vtable is created. Similarly, there may have to be stricter matching rules
+for the functions that go into the vtable, possibly requiring an exact match.
+Relaxed virtual could relax both restrictions, if we allow different vtable
+at different conversion (struct to trait reference) sites. If it is allowed
+local functions being bound to a vtable could cause issues when they go out
+of scope, however this should follow the lifetime rules most C programs
+already follow implicitly.
+
+Most vtables should be stored statically, the only exception being some of
+the relaxed vtables that could have local function pointers. These may be able
+to be stack allocated. All vtables should be immutable and require no manual
+cleanup.
+
+Access has two main options:
+
+The first is through the use of fat pointers, or a tuple of pointers. When the
+object is converted to a trait reference, the pointers to its vtables are
+stored along side it.
+
+This allows for compatibility with existing structures (such as those imported
+from C) and is the default storage method unless a different one is given.
+
+The other is by inlining the vtable pointer as "intrusive vtables". This adds
+a field to the structure to the vtable. The trait reference then has a single
+pointer to this field, the vtable includes an offset to find the beginning of
+the structure again.
+
+This is used if you specify a vtable field in the structure. If given in the
+trait the vtable pointer in the trait reference can then become a single
+pointer to the vtable field and use that to recover the original object
+pointer as well as retrieve all operations.
+
+trait drawable(otype T) {
+	vtable drawable;
+};
+
+struct line {
+	vtable drawable;
+	vec2 start;
+	vec2 end;
+};
+
+This inline code allows trait references to be converted to plain pointers
+(although they still must be called specially). The vtable field may just be
+an opaque block of memory or it may allow user access to the vtable. If so
+then there should be some way to retrieve the type of the vtable, which will be
+autogenerated and often unique.
+
+
+Keyword Usage:
+
+It may be desirable to add fewer new keywords than discussed in this proposal.
+It is possible that "virtual" could replace both "vtable" above with
+unambiguous contextual meaning. However, for purposes of clarity in the design
+discussion it is beneficial to keep the keywords for separate concepts distinct.
+
+
+Trait References and Operations:
+
+sizeof(drawable) will return the size of the trait object itself. However :
+
+line a_line;
+drawable widget = a_line;
+sizeof(widget);
+
+Will instead return the sizeof the underlying object, although the trait must
+require that its implementation is sized for there to be a meaningful value
+to return. You may also get the size of the trait reference with
+
+sizeof(&widget);
+
+Calling free on a trait reference will free the memory for the object. It will
+leave the vtables alone, as those are (always?) statically allocated.
Index: src/Common/VectorMap.h
===================================================================
--- src/Common/VectorMap.h	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/Common/VectorMap.h	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// ScopedMap.h --
+// VectorMap.h --
 //
 // Author           : Aaron B. Moss
Index: src/ControlStruct/ExceptTranslate.cc
===================================================================
--- src/ControlStruct/ExceptTranslate.cc	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/ControlStruct/ExceptTranslate.cc	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -10,6 +10,6 @@
 // Created On       : Wed Jun 14 16:49:00 2017
 // Last Modified By : Andrew Beach
-// Last Modified On : Wed Jul 12 15:07:00 2017
-// Update Count     : 3
+// Last Modified On : Tus Jul 18 10:09:00 2017
+// Update Count     : 4
 //
 
@@ -50,5 +50,5 @@
 			LinkageSpec::Cforall,
 			/*bitfieldWidth*/ NULL,
-			new BasicType( emptyQualifiers, BasicType::SignedInt ),
+			new BasicType( noQualifiers, BasicType::SignedInt ),
 			/*init*/ NULL
 			);
@@ -59,6 +59,6 @@
 			/*bitfieldWidth*/ NULL,
 			new PointerType(
-				emptyQualifiers,
-				new BasicType( emptyQualifiers, BasicType::SignedInt )
+				noQualifiers,
+				new BasicType( noQualifiers, BasicType::SignedInt )
 				),
 			/*init*/ NULL
@@ -69,5 +69,5 @@
 			LinkageSpec::Cforall,
 			/*bitfieldWidth*/ NULL,
-			new BasicType(emptyQualifiers, BasicType::Bool),
+			new BasicType(noQualifiers, BasicType::Bool),
 			/*init*/ NULL
 			);
@@ -78,7 +78,7 @@
 			NULL,
 			new PointerType(
-				emptyQualifiers,
+				noQualifiers,
 				new VoidType(
-					emptyQualifiers
+					noQualifiers
 					),
 				std::list<Attribute *>{new Attribute("unused")}
@@ -143,5 +143,5 @@
 			LinkageSpec::Cforall,
 			NULL,
-			new BasicType( emptyQualifiers, BasicType::SignedInt ),
+			new BasicType( noQualifiers, BasicType::SignedInt ),
 			new SingleInit( throwStmt->get_expr() )
 			);
@@ -444,5 +444,5 @@
 			nullptr,
 			new StructInstType(
-				emptyQualifiers,
+				noQualifiers,
 				hook_decl
 				),
Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/GenPoly/Box.cc	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -202,5 +202,5 @@
 		};
 
-		/// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, and sizeof expressions of polymorphic types with the proper variable
+		/// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, sizeof expressions of polymorphic types with the proper variable, and strips fields from generic struct declarations.
 		class Pass3 final : public PolyMutator {
 		  public:
@@ -210,4 +210,6 @@
 			using PolyMutator::mutate;
 			virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override;
+			virtual Declaration *mutate( StructDecl *structDecl ) override;
+			virtual Declaration *mutate( UnionDecl *unionDecl ) override;
 			virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override;
 			virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override;
@@ -1868,4 +1870,19 @@
 		}
 
+		/// Strips the members from a generic aggregate
+		void stripGenericMembers(AggregateDecl* decl) {
+			if ( ! decl->get_parameters().empty() ) decl->get_members().clear();
+		}
+
+		Declaration *Pass3::mutate( StructDecl *structDecl ) {
+			stripGenericMembers( structDecl );
+			return structDecl;
+		}
+		
+		Declaration *Pass3::mutate( UnionDecl *unionDecl ) {
+			stripGenericMembers( unionDecl );
+			return unionDecl;
+		}
+
 		TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
 //   Initializer *init = 0;
Index: src/Parser/ExpressionNode.cc
===================================================================
--- src/Parser/ExpressionNode.cc	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/Parser/ExpressionNode.cc	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Sat May 16 13:17:07 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 15 16:09:04 2017
-// Update Count     : 549
+// Last Modified By : Andrew Beach
+// Last Modified On : Tus Jul 18 10:08:00 2017
+// Update Count     : 550
 //
 
@@ -46,5 +46,5 @@
 // type.
 
-Type::Qualifiers emptyQualifiers;				// no qualifiers on constants
+Type::Qualifiers noQualifiers;				// no qualifiers on constants
 
 static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
@@ -118,5 +118,5 @@
 	} // if
 
-	Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str, v ) );
+	Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
 	delete &str;										// created by lex
 	return ret;
@@ -153,5 +153,5 @@
 	} // if
 
-	Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str, v ) );
+	Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
 	delete &str;										// created by lex
 	return ret;
@@ -159,5 +159,5 @@
 
 Expression *build_constantChar( const std::string & str ) {
-	Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
+	Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
 	delete &str;										// created by lex
 	return ret;
@@ -166,5 +166,5 @@
 ConstantExpr *build_constantStr( const std::string & str ) {
 	// string should probably be a primitive type
-	ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
+	ArrayType *at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
 								   new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ),  // +1 for '\0' and -2 for '"'
 								   false, false );
@@ -176,5 +176,5 @@
 
 Expression *build_constantZeroOne( const std::string & str ) {
-	Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str,
+	Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( noQualifiers ) : (Type*)new OneType( noQualifiers ), str,
 												   str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) );
 	delete &str;										// created by lex
Index: src/Parser/TypeData.cc
===================================================================
--- src/Parser/TypeData.cc	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/Parser/TypeData.cc	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:12:51 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Fri Jul 14 16:58:00 2017
-// Update Count     : 565
+// Last Modified On : Tus Jul 18 10:10:00 2017
+// Update Count     : 566
 //
 
@@ -454,8 +454,8 @@
 	  case TypeData::Builtin:
 		if(td->builtintype == DeclarationNode::Zero) {
-			return new ZeroType( emptyQualifiers );
+			return new ZeroType( noQualifiers );
 		}
 		else if(td->builtintype == DeclarationNode::One) {
-			return new OneType( emptyQualifiers );
+			return new OneType( noQualifiers );
 		}
 		else {
Index: src/Parser/parserutility.cc
===================================================================
--- src/Parser/parserutility.cc	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/Parser/parserutility.cc	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Sat May 16 15:30:39 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jun 28 22:11:32 2017
-// Update Count     : 7
+// Last Modified By : Andrew Beach
+// Last Modified On : Tus Jul 18 10:12:00 2017
+// Update Count     : 8
 //
 
@@ -26,5 +26,5 @@
 	UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) );
 	comparison->get_args().push_back( orig );
-	comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0", (unsigned long long int)0 ) ) );
+	comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( noQualifiers ), "0", (unsigned long long int)0 ) ) );
 	return new CastExpr( comparison, new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
 }
Index: src/SynTree/Type.h
===================================================================
--- src/SynTree/Type.h	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/SynTree/Type.h	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Mar 23 16:16:36 2017
-// Update Count     : 149
+// Last Modified By : Andrew Beach
+// Last Modified On : Tus Jul 18 10:06:00 2017
+// Update Count     : 150
 //
 
@@ -172,5 +172,5 @@
 };
 
-extern Type::Qualifiers emptyQualifiers;				// no qualifiers on constants
+extern Type::Qualifiers noQualifiers;				// no qualifiers on constants
 
 class VoidType : public Type {
Index: src/libcfa/concurrency/alarm.c
===================================================================
--- src/libcfa/concurrency/alarm.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/alarm.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -31,4 +31,42 @@
 
 //=============================================================================================
+// time type
+//=============================================================================================
+
+#define one_second         1_000_000_000ul
+#define one_milisecond         1_000_000ul
+#define one_microsecond            1_000ul
+#define one_nanosecond                 1ul
+
+__cfa_time_t zero_time = { 0 };
+
+void ?{}( __cfa_time_t * this ) { this->val = 0; }
+void ?{}( __cfa_time_t * this, zero_t zero ) { this->val = 0; }
+
+void ?{}( itimerval * this, __cfa_time_t * alarm ) {
+	this->it_value.tv_sec = alarm->val / one_second;			// seconds
+	this->it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds
+	this->it_interval.tv_sec = 0;
+	this->it_interval.tv_usec = 0;
+}
+
+
+void ?{}( __cfa_time_t * this, timespec * curr ) {
+	uint64_t secs  = curr->tv_sec;
+	uint64_t nsecs = curr->tv_nsec;
+	this->val = (secs * one_second) + nsecs;
+}
+
+__cfa_time_t ?=?( __cfa_time_t * this, zero_t rhs ) {
+	this->val = 0;
+	return *this;
+}
+
+__cfa_time_t from_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
+__cfa_time_t from_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
+__cfa_time_t from_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
+__cfa_time_t from_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
+
+//=============================================================================================
 // Clock logic
 //=============================================================================================
@@ -37,16 +75,9 @@
 	timespec curr;
 	clock_gettime( CLOCK_REALTIME, &curr );
-	__cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
-	// LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );
-	return curr_time;
+	return (__cfa_time_t){ &curr };
 }
 
 void __kernel_set_timer( __cfa_time_t alarm ) {
-	LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %llu\n", (__cfa_time_t)alarm );
-	itimerval val;
-	val.it_value.tv_sec = alarm / TIMEGRAN;			// seconds
-	val.it_value.tv_usec = max( (alarm % TIMEGRAN) / ( TIMEGRAN / 1_000_000L ), 1000 ); // microseconds
-	val.it_interval.tv_sec = 0;
-	val.it_interval.tv_usec = 0;
+	itimerval val = { &alarm };
 	setitimer( ITIMER_REAL, &val, NULL );
 }
@@ -56,5 +87,5 @@
 //=============================================================================================
 
-void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = 0, __cfa_time_t period = 0 ) {
+void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
 	this->thrd = thrd;
 	this->alarm = alarm;
@@ -65,5 +96,5 @@
 }
 
-void ?{}( alarm_node_t * this, processor   * proc, __cfa_time_t alarm = 0, __cfa_time_t period = 0 ) {
+void ?{}( alarm_node_t * this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
 	this->proc = proc;
 	this->alarm = alarm;
@@ -153,20 +184,18 @@
 
 void register_self( alarm_node_t * this ) {
+	alarm_list_t * alarms = &event_kernel->alarms;
+
 	disable_interrupts();
-	verify( !systemProcessor->pending_alarm );
-	lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
+	lock( &event_kernel->lock DEBUG_CTX2 );
 	{
-		verify( validate( &systemProcessor->alarms ) );
-		bool first = !systemProcessor->alarms.head;
-
-		insert( &systemProcessor->alarms, this );
-		if( systemProcessor->pending_alarm ) {
-			tick_preemption();
+		verify( validate( alarms ) );
+		bool first = !alarms->head;
+
+		insert( alarms, this );
+		if( first ) {
+			__kernel_set_timer( alarms->head->alarm - __kernel_get_time() );
 		}
-		if( first ) {
-			__kernel_set_timer( systemProcessor->alarms.head->alarm - __kernel_get_time() );
-		}
-	}
-	unlock( &systemProcessor->alarm_lock );
+	}
+	unlock( &event_kernel->lock );
 	this->set = true;
 	enable_interrupts( DEBUG_CTX );
@@ -174,14 +203,12 @@
 
 void unregister_self( alarm_node_t * this ) {
-	// LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : unregister %p start\n", this );
 	disable_interrupts();
-	lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
+	lock( &event_kernel->lock DEBUG_CTX2 );
 	{
-		verify( validate( &systemProcessor->alarms ) );
-		remove( &systemProcessor->alarms, this );
-	}
-	unlock( &systemProcessor->alarm_lock );
+		verify( validate( &event_kernel->alarms ) );
+		remove( &event_kernel->alarms, this );
+	}
+	unlock( &event_kernel->lock );
 	enable_interrupts( DEBUG_CTX );
 	this->set = false;
-	// LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Kernel : unregister %p end\n", this );
-}
+}
Index: src/libcfa/concurrency/alarm.h
===================================================================
--- src/libcfa/concurrency/alarm.h	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/alarm.h	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -23,14 +23,64 @@
 #include <assert.h>
 
-typedef uint64_t __cfa_time_t;
-
 struct thread_desc;
 struct processor;
+
+struct timespec;
+struct itimerval;
+
+//=============================================================================================
+// time type
+//=============================================================================================
+
+struct __cfa_time_t {
+	uint64_t val;
+};
+
+// ctors
+void ?{}( __cfa_time_t * this );
+void ?{}( __cfa_time_t * this, zero_t zero );
+void ?{}( __cfa_time_t * this, timespec * curr );
+void ?{}( itimerval * this, __cfa_time_t * alarm );
+
+__cfa_time_t ?=?( __cfa_time_t * this, zero_t rhs );
+
+// logical ops
+static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; }
+static inline bool ?!=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val != rhs.val; }
+static inline bool ?>? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >  rhs.val; }
+static inline bool ?<? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <  rhs.val; }
+static inline bool ?>=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >= rhs.val; }
+static inline bool ?<=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <= rhs.val; }
+
+static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; }
+static inline bool ?!=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val != rhs; }
+static inline bool ?>? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >  rhs; }
+static inline bool ?<? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <  rhs; }
+static inline bool ?>=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >= rhs; }
+static inline bool ?<=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <= rhs; }
+
+// addition/substract
+static inline __cfa_time_t ?+?( __cfa_time_t lhs, __cfa_time_t rhs ) {
+	__cfa_time_t ret;
+	ret.val = lhs.val + rhs.val;
+	return ret;
+}
+
+static inline __cfa_time_t ?-?( __cfa_time_t lhs, __cfa_time_t rhs ) {
+	__cfa_time_t ret;
+	ret.val = lhs.val - rhs.val;
+	return ret;
+}
+
+__cfa_time_t from_s ( uint64_t );
+__cfa_time_t from_ms( uint64_t );
+__cfa_time_t from_us( uint64_t );
+__cfa_time_t from_ns( uint64_t );
+
+extern __cfa_time_t zero_time;
 
 //=============================================================================================
 // Clock logic
 //=============================================================================================
-
-#define TIMEGRAN 1_000_000_000L				// nanosecond granularity, except for timeval
 
 __cfa_time_t __kernel_get_time();
@@ -57,6 +107,6 @@
 typedef alarm_node_t ** __alarm_it_t;
 
-void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = 0, __cfa_time_t period = 0 );
-void ?{}( alarm_node_t * this, processor   * proc, __cfa_time_t alarm = 0, __cfa_time_t period = 0 );
+void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
+void ?{}( alarm_node_t * this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
 void ^?{}( alarm_node_t * this );
 
Index: src/libcfa/concurrency/coroutine
===================================================================
--- src/libcfa/concurrency/coroutine	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/coroutine	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -63,5 +63,5 @@
 
 // Get current coroutine
-extern volatile thread_local coroutine_desc * this_coroutine;
+extern thread_local coroutine_desc * volatile this_coroutine;
 
 // Private wrappers for context switch and stack creation
Index: src/libcfa/concurrency/coroutine.c
===================================================================
--- src/libcfa/concurrency/coroutine.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/coroutine.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -26,11 +26,9 @@
 }
 
-#include "kernel"
-#include "libhdr.h"
+#include "kernel_private.h"
 
 #define __CFA_INVOKE_PRIVATE__
 #include "invoke.h"
 
-extern volatile thread_local processor * this_processor;
 
 //-----------------------------------------------------------------------------
Index: src/libcfa/concurrency/kernel
===================================================================
--- src/libcfa/concurrency/kernel	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/kernel	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -28,8 +28,8 @@
 //-----------------------------------------------------------------------------
 // Locks
-bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );
-void lock      ( spinlock * DEBUG_CTX_PARAM2 );
-void lock_yield( spinlock * DEBUG_CTX_PARAM2 );
-void unlock    ( spinlock * );
+void lock      ( spinlock * DEBUG_CTX_PARAM2 );       // Lock the spinlock, spin if already acquired
+void lock_yield( spinlock * DEBUG_CTX_PARAM2 );       // Lock the spinlock, yield repeatedly if already acquired
+bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );       // Lock the spinlock, return false if already acquired
+void unlock    ( spinlock * );                        // Unlock the spinlock
 
 struct semaphore {
@@ -48,6 +48,7 @@
 // Cluster
 struct cluster {
-	__thread_queue_t ready_queue;
-	spinlock lock;
+	spinlock ready_queue_lock;                      // Ready queue locks
+	__thread_queue_t ready_queue;                   // Ready queue for threads
+	unsigned long long int preemption;              // Preemption rate on this cluster
 };
 
@@ -76,20 +77,26 @@
 static inline void ^?{}(FinishAction * this) {}
 
+// Processor
+// Wrapper around kernel threads
 struct processor {
-	struct processorCtx_t * runner;
-	cluster * cltr;
-	pthread_t kernel_thread;
+	// Main state
+	struct processorCtx_t * runner;                 // Coroutine ctx who does keeps the state of the processor
+	cluster * cltr;                                 // Cluster from which to get threads
+	pthread_t kernel_thread;                        // Handle to pthreads
 
-	semaphore terminated;
-	volatile bool is_terminated;
+	// Termination
+	volatile bool do_terminate;                     // Set to true to notify the processor should terminate
+	semaphore terminated;                           // Termination synchronisation
 
-	struct FinishAction finish;
+	// RunThread data
+	struct FinishAction finish;                     // Action to do after a thread is ran
 
-	struct alarm_node_t * preemption_alarm;
-	unsigned int preemption;
+	// Preemption data
+	struct alarm_node_t * preemption_alarm;         // Node which is added in the discrete event simulaiton
+	bool pending_preemption;                        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
 
-	bool pending_preemption;
-
-	char * last_enable;
+#ifdef __CFA_DEBUG__
+	char * last_enable;                             // Last function to enable preemption on this processor
+#endif
 };
 
Index: src/libcfa/concurrency/kernel.c
===================================================================
--- src/libcfa/concurrency/kernel.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/kernel.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -42,14 +42,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 +55,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 +84,5 @@
 
 	this->limit = (void *)(((intptr_t)this->base) - this->size);
-	this->context = &mainThreadCtxStorage;
+	this->context = &storage_mainThreadCtx;
 	this->top = this->base;
 }
@@ -125,5 +124,5 @@
 
 void ?{}(processor * this) {
-	this{ systemCluster };
+	this{ mainCluster };
 }
 
@@ -131,7 +130,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 +140,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 +161,7 @@
 void ?{}(cluster * this) {
 	( &this->ready_queue ){};
-	( &this->lock ){};
+	( &this->ready_queue_lock ){};
+
+	this->preemption = default_preemption();
 }
 
@@ -199,5 +186,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 +330,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 +339,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 +439,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 +446,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 +487,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 +498,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
Index: src/libcfa/concurrency/kernel_private.h
===================================================================
--- src/libcfa/concurrency/kernel_private.h	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/kernel_private.h	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -31,5 +31,5 @@
 extern "C" {
 	void disable_interrupts();
-	void enable_interrupts_noRF();
+	void enable_interrupts_noPoll();
 	void enable_interrupts( DEBUG_CTX_PARAM );
 }
@@ -45,4 +45,5 @@
 thread_desc * nextThread(cluster * this);
 
+//Block current thread and release/wake-up the following resources
 void BlockInternal(void);
 void BlockInternal(spinlock * lock);
@@ -65,18 +66,15 @@
 void spin(processor * this, unsigned int * spin_count);
 
-struct system_proc_t {
-	processor proc;
-
+struct event_kernel_t {
 	alarm_list_t alarms;
-	spinlock alarm_lock;
-
-	bool pending_alarm;
+	spinlock lock;
 };
 
-extern cluster * systemCluster;
-extern system_proc_t * systemProcessor;
-extern volatile thread_local processor * this_processor;
-extern volatile thread_local coroutine_desc * this_coroutine;
-extern volatile thread_local thread_desc * this_thread;
+extern event_kernel_t * event_kernel;
+
+extern thread_local coroutine_desc * volatile this_coroutine;
+extern thread_local thread_desc *    volatile this_thread;
+extern thread_local processor *      volatile this_processor;
+
 extern volatile thread_local bool preemption_in_progress;
 extern volatile thread_local unsigned short disable_preempt_count;
@@ -91,4 +89,8 @@
 extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
 
+//-----------------------------------------------------------------------------
+// Utils
+#define KERNEL_STORAGE(T,X) static char storage_##X[sizeof(T)]
+
 #endif //KERNEL_PRIVATE_H
 
Index: src/libcfa/concurrency/preemption.c
===================================================================
--- src/libcfa/concurrency/preemption.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/preemption.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -34,24 +34,32 @@
 #endif
 
+//TODO move to defaults
 #define __CFA_DEFAULT_PREEMPTION__ 10000
 
+//TODO move to defaults
 __attribute__((weak)) unsigned int default_preemption() {
 	return __CFA_DEFAULT_PREEMPTION__;
 }
 
+// Short hands for signal context information
 #define __CFA_SIGCXT__ ucontext_t *
 #define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt
 
+// FwdDeclarations : timeout handlers
 static void preempt( processor   * this );
 static void timeout( thread_desc * this );
 
+// FwdDeclarations : Signal handlers
 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ );
-void sigHandler_alarm    ( __CFA_SIGPARMS__ );
 void sigHandler_segv     ( __CFA_SIGPARMS__ );
 void sigHandler_abort    ( __CFA_SIGPARMS__ );
 
+// FwdDeclarations : sigaction wrapper
 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags );
-LIB_DEBUG_DO( bool validate( alarm_list_t * this ); )
-
+
+// FwdDeclarations : alarm thread main
+void * alarm_loop( __attribute__((unused)) void * args );
+
+// Machine specific register name
 #ifdef __x86_64__
 #define CFA_REG_IP REG_RIP
@@ -60,4 +68,12 @@
 #endif
 
+KERNEL_STORAGE(event_kernel_t, event_kernel);         // private storage for event kernel
+event_kernel_t * event_kernel;                        // kernel public handle to even kernel
+static pthread_t alarm_thread;                        // pthread handle to alarm thread
+
+void ?{}(event_kernel_t * this) {
+	(&this->alarms){};
+	(&this->lock){};
+}
 
 //=============================================================================================
@@ -65,13 +81,21 @@
 //=============================================================================================
 
+// Get next expired node
+static inline alarm_node_t * get_expired( alarm_list_t * alarms, __cfa_time_t currtime ) {
+	if( !alarms->head ) return NULL;                          // If no alarms return null
+	if( alarms->head->alarm >= currtime ) return NULL;        // If alarms head not expired return null
+	return pop(alarms);                                       // Otherwise just pop head
+}
+
+// Tick one frame of the Discrete Event Simulation for alarms
 void tick_preemption() {
-	alarm_list_t * alarms = &systemProcessor->alarms;
-	__cfa_time_t currtime = __kernel_get_time();
-
-	// LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Ticking preemption @ %llu\n", currtime );
-	while( alarms->head && alarms->head->alarm < currtime ) {
-		alarm_node_t * node = pop(alarms);
-		// LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ticking %p\n", node );
-
+	alarm_node_t * node = NULL;                     // Used in the while loop but cannot be declared in the while condition
+	alarm_list_t * alarms = &event_kernel->alarms;  // Local copy for ease of reading
+	__cfa_time_t currtime = __kernel_get_time();    // Check current time once so we everything "happens at once"
+
+	//Loop throught every thing expired
+	while( node = get_expired( alarms, currtime ) ) {
+
+		// Check if this is a kernel
 		if( node->kernel_alarm ) {
 			preempt( node->proc );
@@ -81,30 +105,22 @@
 		}
 
-		verify( validate( alarms ) );
-
+		// Check if this is a periodic alarm
 		__cfa_time_t period = node->period;
 		if( period > 0 ) {
-			node->alarm = currtime + period;
-			// LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Reinsert %p @ %llu (%llu + %llu)\n", node, node->alarm, currtime, period );
-			insert( alarms, node );
+			node->alarm = currtime + period;    // Alarm is periodic, add currtime to it (used cached current time)
+			insert( alarms, node );             // Reinsert the node for the next time it triggers
 		}
 		else {
-			node->set = false;
-		}
-	}
-
-	if( alarms->head ) {
-		__kernel_set_timer( alarms->head->alarm - currtime );
-	}
-
-	verify( validate( alarms ) );
-	// LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ticking preemption done\n" );
-}
-
+			node->set = false;                  // Node is one-shot, just mark it as not pending
+		}
+	}
+
+	// If there are still alarms pending, reset the timer
+	if( alarms->head ) { __kernel_set_timer( alarms->head->alarm - currtime ); }
+}
+
+// Update the preemption of a processor and notify interested parties
 void update_preemption( processor * this, __cfa_time_t duration ) {
-	LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : %p updating preemption to %llu\n", this, duration );
-
 	alarm_node_t * alarm = this->preemption_alarm;
-	duration *= 1000;
 
 	// Alarms need to be enabled
@@ -136,20 +152,20 @@
 
 extern "C" {
+	// Disable interrupts by incrementing the counter
 	void disable_interrupts() {
 		__attribute__((unused)) unsigned short new_val = __atomic_add_fetch_2( &disable_preempt_count, 1, __ATOMIC_SEQ_CST );
-		verify( new_val < (unsigned short)65_000 );
-		verify( new_val != (unsigned short) 0 );
-	}
-
-	void enable_interrupts_noRF() {
-		__attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST );
-		verify( prev != (unsigned short) 0 );
-	}
-
+		verify( new_val < 65_000u );              // If this triggers someone is disabling interrupts without enabling them
+	}
+
+	// Enable interrupts by decrementing the counter
+	// If counter reaches 0, execute any pending CtxSwitch
 	void enable_interrupts( DEBUG_CTX_PARAM ) {
-		processor * proc   = this_processor;
-		thread_desc * thrd = this_thread;
+		processor * proc   = this_processor;      // Cache the processor now since interrupts can start happening after the atomic add
+		thread_desc * thrd = this_thread;         // Cache the thread now since interrupts can start happening after the atomic add
+
 		unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST );
-		verify( prev != (unsigned short) 0 );
+		verify( prev != 0u );                     // If this triggers someone is enabled already enabled interruptsverify( prev != 0u );
+
+		// Check if we need to prempt the thread because an interrupt was missed
 		if( prev == 1 && proc->pending_preemption ) {
 			proc->pending_preemption = false;
@@ -157,8 +173,17 @@
 		}
 
+		// For debugging purposes : keep track of the last person to enable the interrupts
 		LIB_DEBUG_DO( proc->last_enable = caller; )
 	}
-}
-
+
+	// Disable interrupts by incrementint the counter
+	// Don't execute any pending CtxSwitch even if counter reaches 0
+	void enable_interrupts_noPoll() {
+		__attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST );
+		verify( prev != 0u );                     // If this triggers someone is enabled already enabled interrupts
+	}
+}
+
+// sigprocmask wrapper : unblock a single signal
 static inline void signal_unblock( int sig ) {
 	sigset_t mask;
@@ -171,4 +196,5 @@
 }
 
+// sigprocmask wrapper : block a single signal
 static inline void signal_block( int sig ) {
 	sigset_t mask;
@@ -181,36 +207,44 @@
 }
 
-static inline bool preemption_ready() {
-	return disable_preempt_count == 0 && !preemption_in_progress;
-}
-
-static inline void defer_ctxSwitch() {
-	this_processor->pending_preemption = true;
-}
-
-static inline void defer_alarm() {
-	systemProcessor->pending_alarm = true;
-}
-
+// kill wrapper : signal a processor
 static void preempt( processor * this ) {
 	pthread_kill( this->kernel_thread, SIGUSR1 );
 }
 
+// reserved for future use
 static void timeout( thread_desc * this ) {
 	//TODO : implement waking threads
 }
 
+
+// Check if a CtxSwitch signal handler shoud defer
+// If true  : preemption is safe
+// If false : preemption is unsafe and marked as pending
+static inline bool preemption_ready() {
+	bool ready = disable_preempt_count == 0 && !preemption_in_progress; // Check if preemption is safe
+	this_processor->pending_preemption = !ready;                        // Adjust the pending flag accordingly
+	return ready;
+}
+
 //=============================================================================================
 // Kernel Signal Startup/Shutdown logic
 //=============================================================================================
 
-static pthread_t alarm_thread;
-void * alarm_loop( __attribute__((unused)) void * args );
-
+// Startup routine to activate preemption
+// Called from kernel_startup
 void kernel_start_preemption() {
 	LIB_DEBUG_PRINT_SAFE("Kernel : Starting preemption\n");
-	__kernel_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO );
-	// __kernel_sigaction( SIGSEGV, sigHandler_segv     , SA_SIGINFO );
-	// __kernel_sigaction( SIGBUS , sigHandler_segv     , SA_SIGINFO );
+
+	// Start with preemption disabled until ready
+	disable_preempt_count = 1;
+
+	// Initialize the event kernel
+	event_kernel = (event_kernel_t *)&storage_event_kernel;
+	event_kernel{};
+
+	// Setup proper signal handlers
+	__kernel_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO );         // CtxSwitch handler
+	// __kernel_sigaction( SIGSEGV, sigHandler_segv     , SA_SIGINFO );      // Failure handler
+	// __kernel_sigaction( SIGBUS , sigHandler_segv     , SA_SIGINFO );      // Failure handler
 
 	signal_block( SIGALRM );
@@ -219,22 +253,34 @@
 }
 
+// Shutdown routine to deactivate preemption
+// Called from kernel_shutdown
 void kernel_stop_preemption() {
 	LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopping\n");
 
+	// Block all signals since we are already shutting down
 	sigset_t mask;
 	sigfillset( &mask );
 	sigprocmask( SIG_BLOCK, &mask, NULL );
 
+	// Notify the alarm thread of the shutdown
 	sigval val = { 1 };
 	pthread_sigqueue( alarm_thread, SIGALRM, val );
+
+	// Wait for the preemption thread to finish
 	pthread_join( alarm_thread, NULL );
+
+	// Preemption is now fully stopped
+
 	LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopped\n");
 }
 
+// Raii ctor/dtor for the preemption_scope
+// Used by thread to control when they want to receive preemption signals
 void ?{}( preemption_scope * this, processor * proc ) {
-	(&this->alarm){ proc };
+	(&this->alarm){ proc, zero_time, zero_time };
 	this->proc = proc;
 	this->proc->preemption_alarm = &this->alarm;
-	update_preemption( this->proc, this->proc->preemption );
+
+	update_preemption( this->proc, from_us(this->proc->cltr->preemption) );
 }
 
@@ -242,5 +288,5 @@
 	disable_interrupts();
 
-	update_preemption( this->proc, 0 );
+	update_preemption( this->proc, zero_time );
 }
 
@@ -249,19 +295,25 @@
 //=============================================================================================
 
+// Context switch signal handler
+// Receives SIGUSR1 signal and causes the current thread to yield
 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
 	LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
-	if( preemption_ready() ) {
-		preemption_in_progress = true;
-		signal_unblock( SIGUSR1 );
-		this_processor->pending_preemption = false;
-		preemption_in_progress = false;
-		BlockInternal( (thread_desc*)this_thread );
-	}
-	else {
-		defer_ctxSwitch();
-	}
-}
-
+
+	// Check if it is safe to preempt here
+	if( !preemption_ready() ) { return; }
+
+	preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
+	signal_unblock( SIGUSR1 );                          // We are about to CtxSwitch out of the signal handler, let other handlers in
+	preemption_in_progress = false;                     // Clear the in progress flag
+
+	// Preemption can occur here
+
+	BlockInternal( (thread_desc*)this_thread );         // Do the actual CtxSwitch
+}
+
+// Main of the alarm thread
+// Waits on SIGALRM and send SIGUSR1 to whom ever needs it
 void * alarm_loop( __attribute__((unused)) void * args ) {
+	// Block sigalrms to control when they arrive
 	sigset_t mask;
 	sigemptyset( &mask );
@@ -272,20 +324,30 @@
 	}
 
+	// Main loop
 	while( true ) {
+		// Wait for a sigalrm
 		siginfo_t info;
 		int sig = sigwaitinfo( &mask, &info );
+
+		// If another signal arrived something went wrong
 		assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int);
 
 		LIB_DEBUG_PRINT_SAFE("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
+		// Switch on the code (a.k.a. the sender) to
 		switch( info.si_code )
 		{
+		// Timers can apparently be marked as sent for the kernel
+		// In either case, tick preemption
 		case SI_TIMER:
 		case SI_KERNEL:
 			LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread tick\n");
-			lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
+			lock( &event_kernel->lock DEBUG_CTX2 );
 			tick_preemption();
-			unlock( &systemProcessor->alarm_lock );
+			unlock( &event_kernel->lock );
 			break;
+		// Signal was not sent by the kernel but by an other thread
 		case SI_QUEUE:
+			// For now, other thread only signal the alarm thread to shut it down
+			// If this needs to change use info.si_value and handle the case here
 			goto EXIT;
 		}
@@ -297,4 +359,5 @@
 }
 
+// Sigaction wrapper : register an signal handler
 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags ) {
 	struct sigaction act;
@@ -312,10 +375,9 @@
 }
 
-typedef void (*sa_handler_t)(int);
-
+// Sigaction wrapper : restore default handler
 static void __kernel_sigdefault( int sig ) {
 	struct sigaction act;
 
-	// act.sa_handler = SIG_DFL;
+	act.sa_handler = SIG_DFL;
 	act.sa_flags = 0;
 	sigemptyset( &act.sa_mask );
Index: src/libcfa/concurrency/thread
===================================================================
--- src/libcfa/concurrency/thread	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/thread	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -54,5 +54,5 @@
 }
 
-extern volatile thread_local thread_desc * this_thread;
+extern thread_local thread_desc * volatile this_thread;
 
 forall( dtype T | is_thread(T) )
Index: src/libcfa/concurrency/thread.c
===================================================================
--- src/libcfa/concurrency/thread.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/libcfa/concurrency/thread.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -87,5 +87,5 @@
 
 void yield( void ) {
-	BlockInternal( (thread_desc *)this_thread );
+	BlockInternal( this_thread );
 }
 
Index: c/tests/.expect/concurrent/sched-int-barge.txt
===================================================================
--- src/tests/.expect/concurrent/sched-int-barge.txt	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ 	(revision )
@@ -1,100 +1,0 @@
-1000
-2000
-3000
-4000
-5000
-6000
-7000
-8000
-9000
-10000
-11000
-12000
-13000
-14000
-15000
-16000
-17000
-18000
-19000
-20000
-21000
-22000
-23000
-24000
-25000
-26000
-27000
-28000
-29000
-30000
-31000
-32000
-33000
-34000
-35000
-36000
-37000
-38000
-39000
-40000
-41000
-42000
-43000
-44000
-45000
-46000
-47000
-48000
-49000
-50000
-51000
-52000
-53000
-54000
-55000
-56000
-57000
-58000
-59000
-60000
-61000
-62000
-63000
-64000
-65000
-66000
-67000
-68000
-69000
-70000
-71000
-72000
-73000
-74000
-75000
-76000
-77000
-78000
-79000
-80000
-81000
-82000
-83000
-84000
-85000
-86000
-87000
-88000
-89000
-90000
-91000
-92000
-93000
-94000
-95000
-96000
-97000
-98000
-99000
-100000
Index: src/tests/preempt_longrun/Makefile.am
===================================================================
--- src/tests/preempt_longrun/Makefile.am	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/Makefile.am	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -25,5 +25,5 @@
 CC = @CFA_BINDIR@/@CFA_NAME@
 
-TESTS = barge block create disjoint enter enter3 processor stack wait yield
+TESTS = block create disjoint enter enter3 processor stack wait yield
 
 .INTERMEDIATE: ${TESTS}
Index: src/tests/preempt_longrun/Makefile.in
===================================================================
--- src/tests/preempt_longrun/Makefile.in	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/Makefile.in	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -453,5 +453,5 @@
 REPEAT = ${abs_top_srcdir}/tools/repeat -s
 BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -debug -O2 -DPREEMPTION_RATE=${preempt}
-TESTS = barge block create disjoint enter enter3 processor stack wait yield
+TESTS = block create disjoint enter enter3 processor stack wait yield
 all: all-am
 
@@ -635,11 +635,4 @@
 	        TEST_LOGS="$$log_list"; \
 	exit $$?
-barge.log: barge
-	@p='barge'; \
-	b='barge'; \
-	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
-	--log-file $$b.log --trs-file $$b.trs \
-	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
-	"$$tst" $(AM_TESTS_FD_REDIRECT)
 block.log: block
 	@p='block'; \
Index: c/tests/preempt_longrun/barge.c
===================================================================
--- src/tests/preempt_longrun/barge.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../sched-int-barge.c
Index: src/tests/preempt_longrun/create.c
===================================================================
--- src/tests/preempt_longrun/create.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/create.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -1,4 +1,6 @@
 #include <kernel>
 #include <thread>
+
+static const unsigned long N = 2_000ul;
 
 #ifndef PREEMPTION_RATE
@@ -16,5 +18,5 @@
 int main(int argc, char* argv[]) {
 	processor p;
-	for(int i = 0; i < 10_000ul; i++) {
+	for(int i = 0; i < N; i++) {
 		worker_t w[7];
 	}
Index: src/tests/preempt_longrun/enter.c
===================================================================
--- src/tests/preempt_longrun/enter.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/enter.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -3,5 +3,4 @@
 #include <thread>
 
-#undef N
 static const unsigned long N  = 70_000ul;
 
Index: src/tests/preempt_longrun/enter3.c
===================================================================
--- src/tests/preempt_longrun/enter3.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/enter3.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -3,5 +3,4 @@
 #include <thread>
 
-#undef N
 static const unsigned long N  = 50_000ul;
 
Index: src/tests/preempt_longrun/processor.c
===================================================================
--- src/tests/preempt_longrun/processor.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/processor.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -1,4 +1,6 @@
 #include <kernel>
 #include <thread>
+
+static const unsigned long N = 5_000ul;
 
 #ifndef PREEMPTION_RATE
@@ -15,5 +17,5 @@
 
 int main(int argc, char* argv[]) {
-	for(int i = 0; i < 10_000ul; i++) {
+	for(int i = 0; i < N; i++) {
 		processor p;
 	}
Index: src/tests/preempt_longrun/yield.c
===================================================================
--- src/tests/preempt_longrun/yield.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/preempt_longrun/yield.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -1,4 +1,6 @@
 #include <kernel>
 #include <thread>
+
+static const unsigned long N = 325_000ul;
 
 #ifndef PREEMPTION_RATE
@@ -13,5 +15,5 @@
 
 void main(worker_t * this) {
-	for(int i = 0; i < 325_000ul; i++) {
+	for(int i = 0; i < N; i++) {
 		yield();
 	}
Index: src/tests/sched-int-barge.c
===================================================================
--- src/tests/sched-int-barge.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/sched-int-barge.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -5,8 +5,13 @@
 #include <thread>
 
-#ifndef N
-#define N 100_000
+static const unsigned long N = 50_000ul;
+
+#ifndef PREEMPTION_RATE
+#define PREEMPTION_RATE 10_000ul
 #endif
 
+unsigned int default_preemption() {
+	return 0;
+}
 enum state_t { WAIT, SIGNAL, BARGE };
 
@@ -14,5 +19,5 @@
 
 monitor global_data_t {
-	bool done;
+	volatile bool done;
 	int counter;
 	state_t state;
@@ -55,5 +60,5 @@
 		c->do_wait2 = ((unsigned)rand48()) % (c->do_signal);
 
-		// if(c->do_wait1 == c->do_wait2) sout | "Same" | endl;
+		if(c->do_wait1 == c->do_wait2) sout | "Same" | endl;
 	}
 
@@ -93,9 +98,12 @@
 }
 
+static thread_desc * volatile the_threads;
+
 int main(int argc, char* argv[]) {
-	rand48seed(0);
-	processor p;
-	{
-		Threads t[17];
-	}
+        rand48seed(0);
+        processor p;
+        {
+                Threads t[17];
+                the_threads = (thread_desc*)t;
+        }
 }
Index: src/tests/sched-int-block.c
===================================================================
--- src/tests/sched-int-block.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/sched-int-block.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -5,7 +5,15 @@
 #include <thread>
 
-#ifndef N
-#define N 10_000
+#include <time.h>
+
+static const unsigned long N = 5_000ul;
+
+#ifndef PREEMPTION_RATE
+#define PREEMPTION_RATE 10_000ul
 #endif
+
+unsigned int default_preemption() {
+	return PREEMPTION_RATE;
+}
 
 enum state_t { WAITED, SIGNAL, BARGE };
@@ -101,5 +109,5 @@
 
 int main(int argc, char* argv[]) {
-	rand48seed(0);
+	rand48seed( time( NULL ) );
 	done = false;
 	processor p;
Index: src/tests/sched-int-disjoint.c
===================================================================
--- src/tests/sched-int-disjoint.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/sched-int-disjoint.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -4,7 +4,13 @@
 #include <thread>
 
-#ifndef N
-#define N 10_000
+static const unsigned long N = 10_000ul;
+
+#ifndef PREEMPTION_RATE
+#define PREEMPTION_RATE 10_000ul
 #endif
+
+unsigned int default_preemption() {
+	return PREEMPTION_RATE;
+}
 
 enum state_t { WAIT, SIGNAL, BARGE };
Index: src/tests/sched-int-wait.c
===================================================================
--- src/tests/sched-int-wait.c	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/sched-int-wait.c	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -5,7 +5,13 @@
 #include <thread>
 
-#ifndef N
-#define N 10_000
+static const unsigned long N = 10_000ul;
+
+#ifndef PREEMPTION_RATE
+#define PREEMPTION_RATE 10_000ul
 #endif
+
+unsigned int default_preemption() {
+	return PREEMPTION_RATE;
+}
 
 monitor global_t {};
@@ -114,5 +120,5 @@
 int main(int argc, char* argv[]) {
 	waiter_left = 4;
-	processor p;
+	processor p[2];
 	sout | "Starting" | endl;
 	{
Index: src/tests/test.py
===================================================================
--- src/tests/test.py	(revision dab7ac792024c4767a55726e396c9df595df6da0)
+++ src/tests/test.py	(revision 21a5dde1d8e235428996a2e459961bdd313c8f8b)
@@ -221,9 +221,9 @@
 		if   retcode == TestResult.SUCCESS: 	result_txt = "Done"
 		elif retcode == TestResult.TIMEOUT: 	result_txt = "TIMEOUT"
-		else :						result_txt = "ERROR"
+		else :						result_txt = "ERROR code %d" % retcode
 	else :
 		if   retcode == TestResult.SUCCESS: 	result_txt = "PASSED"
 		elif retcode == TestResult.TIMEOUT: 	result_txt = "TIMEOUT"
-		else :						result_txt = "FAILED"
+		else :						result_txt = "FAILED with code %d" % retcode
 
 	#print result with error if needed
