Index: libcfa/src/concurrency/locks.cfa
===================================================================
--- libcfa/src/concurrency/locks.cfa	(revision 3959595fcbab91d221eb882dc5976f75a47b5067)
+++ libcfa/src/concurrency/locks.cfa	(revision a104311c6ccdea00870644d6de297e454928c160)
@@ -51,9 +51,9 @@
 }
 
-void ?{}( mutex_lock & this ) {
+void ?{}( single_acquisition_lock & this ) {
 	((blocking_lock &)this){ false, false };
 }
 
-void ^?{}( mutex_lock & this ) {
+void ^?{}( single_acquisition_lock & this ) {
 	// default
 }
@@ -67,28 +67,27 @@
 }
 
-void ?{}( recursive_mutex_lock & this ) {
+void ?{}( multiple_acquisition_lock & this ) {
 	((blocking_lock &)this){ true, false };
 }
 
-void ^?{}( recursive_mutex_lock & this ) {
+void ^?{}( multiple_acquisition_lock & this ) {
 	// default
 }
 
 void lock( blocking_lock & this ) with( this ) {
-	$thread * thrd = active_thread();
 	lock( lock __cfaabi_dbg_ctx2 );
-	if ( owner == thrd && !multi_acquisition) {
+	if ( owner == active_thread() && !multi_acquisition) {
 		fprintf(stderr, "A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock."); // Possibly throw instead
     	exit(EXIT_FAILURE);
-	} else if ( owner != 0p && owner != thrd ) {
-		append( blocked_threads, thrd );
+	} else if ( owner != 0p && owner != active_thread() ) {
+		append( blocked_threads, active_thread() );
 		wait_count++;
 		unlock( lock );
 		park( );
-	} else if ( owner == thrd && multi_acquisition ) {
+	} else if ( owner == active_thread() && multi_acquisition ) {
 		recursion_count++;
 		unlock( lock );
 	} else {
-		owner = thrd;
+		owner = active_thread();
 		recursion_count = 1;
 		unlock( lock );
@@ -97,12 +96,11 @@
 
 bool try_lock( blocking_lock & this ) with( this ) {
-	$thread * thrd = active_thread();
 	bool ret = false;
 	lock( lock __cfaabi_dbg_ctx2 );
 	if ( owner == 0p ) {
-		owner = thrd;
-		if ( multi_acquisition ) recursion_count = 1;
+		owner = active_thread();
+		recursion_count = 1;
 		ret = true;
-	} else if ( owner == thrd && multi_acquisition ) {
+	} else if ( owner == active_thread() && multi_acquisition ) {
 		recursion_count++;
 		ret = true;
@@ -115,8 +113,8 @@
 	lock( lock __cfaabi_dbg_ctx2 );
 	if ( owner == 0p ){ // no owner implies lock isn't held
-		fprintf( stderr, "There was an attempt to release a lock that isn't held" );
+		fprintf( stderr, "There was an attempt to release a lock that isn't held" ); 
 		return;
-	} else if ( strict_owner && active_thread() ) {
-		fprintf( stderr, "A thread other than the owner attempted to release an owner lock" );
+	} else if ( strict_owner && owner != active_thread() ) {
+		fprintf( stderr, "A thread other than the owner attempted to release an owner lock" ); 
 		return;
 	}
@@ -125,5 +123,5 @@
 		$thread * thrd = pop_head( blocked_threads );
 		owner = thrd;
-		recursion_count = ( thrd && multi_acquisition ? 1 : 0 );
+		recursion_count = ( thrd ? 1 : 0 );
 		wait_count--;
 		unpark( thrd );
@@ -153,7 +151,7 @@
 	} else {
 		owner = t;
-		if ( multi_acquisition ) recursion_count = 1;
+		recursion_count = 1;
 		#if !defined( __CFA_NO_STATISTICS__ )
-			kernelTLS.this_stats = t->curr_cluster->stats;
+			//kernelTLS.this_stats = t->curr_cluster->stats;
 		#endif
 		unpark( t );
@@ -165,11 +163,11 @@
     lock( lock __cfaabi_dbg_ctx2 );
 	if ( owner == 0p ){ // no owner implies lock isn't held
-		fprintf( stderr, "A lock that is not held was passed to a synchronization lock" );
-	} else if ( strict_owner && active_thread() ) {
-		fprintf( stderr, "A thread other than the owner of a lock passed it to a synchronization lock" );
+		fprintf( stderr, "A lock that is not held was passed to a synchronization lock" ); 
+	} else if ( strict_owner && owner != active_thread() ) {
+		fprintf( stderr, "A thread other than the owner of a lock passed it to a synchronization lock" ); 
 	} else {
 		$thread * thrd = pop_head( blocked_threads );
 		owner = thrd;
-		recursion_count = ( thrd && multi_acquisition ? 1 : 0 );
+		recursion_count = ( thrd ? 1 : 0 );
 		wait_count--;
 		unpark( thrd );
@@ -184,50 +182,74 @@
 // This is temporary until an inheritance bug is fixed
 
-void lock( mutex_lock & this ){
+void lock( single_acquisition_lock & this ){
 	lock( (blocking_lock &)this );
 }
 
-void unlock( mutex_lock & this ){
+void unlock( single_acquisition_lock & this ){
 	unlock( (blocking_lock &)this );
 }
 
-void add_( mutex_lock & this, struct $thread * t ){
+void add_( single_acquisition_lock & this, struct $thread * t ){
 	add_( (blocking_lock &)this, t );
 }
 
-void remove_( mutex_lock & this ){
+void remove_( single_acquisition_lock & this ){
 	remove_( (blocking_lock &)this );
 }
 
-void set_recursion_count( mutex_lock & this, size_t recursion ){
+void set_recursion_count( single_acquisition_lock & this, size_t recursion ){
 	set_recursion_count( (blocking_lock &)this, recursion );
 }
 
-size_t get_recursion_count( mutex_lock & this ){
-	get_recursion_count( (blocking_lock &)this );
-}
-
-void lock( recursive_mutex_lock & this ){
+size_t get_recursion_count( single_acquisition_lock & this ){
+	return get_recursion_count( (blocking_lock &)this );
+}
+
+void lock( owner_lock & this ){
 	lock( (blocking_lock &)this );
 }
 
-void unlock( recursive_mutex_lock & this ){
+void unlock( owner_lock & this ){
 	unlock( (blocking_lock &)this );
 }
 
-void add_( recursive_mutex_lock & this, struct $thread * t ){
+void add_( owner_lock & this, struct $thread * t ){
 	add_( (blocking_lock &)this, t );
 }
 
-void remove_( recursive_mutex_lock & this ){
+void remove_( owner_lock & this ){
 	remove_( (blocking_lock &)this );
 }
 
-void set_recursion_count( recursive_mutex_lock & this, size_t recursion ){
+void set_recursion_count( owner_lock & this, size_t recursion ){
 	set_recursion_count( (blocking_lock &)this, recursion );
 }
 
-size_t get_recursion_count( recursive_mutex_lock & this ){
-	get_recursion_count( (blocking_lock &)this );
+size_t get_recursion_count( owner_lock & this ){
+	return get_recursion_count( (blocking_lock &)this );
+}
+
+void lock( multiple_acquisition_lock & this ){
+	lock( (blocking_lock &)this );
+}
+
+void unlock( multiple_acquisition_lock & this ){
+	unlock( (blocking_lock &)this );
+}
+
+void add_( multiple_acquisition_lock & this, struct $thread * t ){
+	add_( (blocking_lock &)this, t );
+}
+
+void remove_( multiple_acquisition_lock & this ){
+	remove_( (blocking_lock &)this );
+}
+
+void set_recursion_count( multiple_acquisition_lock & this, size_t recursion ){
+	set_recursion_count( (blocking_lock &)this, recursion );
+}
+
+size_t get_recursion_count( multiple_acquisition_lock & this ){
+	return get_recursion_count( (blocking_lock &)this );
 }
 
@@ -244,10 +266,8 @@
 	    	info_thread(L) * copy = *i;
 			remove( cond->blocked_threads, i );		 //remove this thread O(1)
-			cond->wait_count--;
+			cond->count--;
 			if( !copy->lock ) {
-				unlock( cond->lock );
 				#if !defined( __CFA_NO_STATISTICS__ )
-					#warning unprotected access to tls TODO discuss this
-					kernelTLS.this_stats = copy->t->curr_cluster->stats;
+					//kernelTLS.this_stats = copy->t->curr_cluster->stats;
 				#endif
 				unpark( copy->t );
@@ -285,6 +305,6 @@
 		bool ret = !!blocked_threads;
 		info_thread(L) * popped = pop_head( blocked_threads );
-		popped->listed = false;
 		if(popped != 0p) {
+			popped->listed = false;
 			count--;
 			if (popped->lock) {
@@ -303,6 +323,6 @@
 		while( blocked_threads ) {
 			info_thread(L) * popped = pop_head( blocked_threads );
-			popped->listed = false;
 			if(popped != 0p){
+				popped->listed = false;
 				count--;
 				if (popped->lock) {
@@ -341,5 +361,5 @@
 			remove_( *i.lock );
 		}
-
+		
 		unlock( lock );
 		park( ); // blocks here
@@ -385,5 +405,5 @@
 		queue_info_thread( this, i );
 	}
-
+	
 	void wait( condition_variable(L) & this, Duration duration ) with(this) {
 		info_thread( L ) i = { active_thread() };
@@ -391,5 +411,5 @@
 	}
 
-	void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) {
+	void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 
 		info_thread( L ) i = { active_thread(), info };
 		queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
@@ -417,5 +437,5 @@
 		queue_info_thread( this, i );
 	}
-
+	
 	void wait( condition_variable(L) & this, L & l, Duration duration ) with(this) {
 		info_thread(L) i = { active_thread() };
@@ -423,5 +443,5 @@
 		queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
 	}
-
+	
 	void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) {
 		info_thread(L) i = { active_thread(), info };
@@ -429,5 +449,5 @@
 		queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
 	}
-
+	
 	void wait( condition_variable(L) & this, L & l, Time time ) with(this) {
 		info_thread(L) i = { active_thread() };
@@ -435,5 +455,5 @@
 		queue_info_thread_timeout(this, i, time );
 	}
-
+	
 	void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) {
 		info_thread(L) i = { active_thread(), info };
@@ -442,2 +462,54 @@
 	}
 }
+
+// thread T1 {};
+// thread T2 {};
+
+// multiple_acquisition_lock m;
+// condition_variable( multiple_acquisition_lock ) c;
+
+// void main( T1 & this ) {
+// 	printf("T1 start\n");
+// 	lock(m);
+// 	printf("%d\n", counter(c));
+// 	if(empty(c)) {
+// 		printf("T1 wait\n");
+// 		wait(c,m,12);
+// 	}else{
+// 		printf("%d\n", front(c));
+// 		notify_one(c);
+// 	}
+// 	unlock(m);
+// 	printf("curr thd in main %p \n", active_thread());
+// 	printf("T1 waits for 2s\n");
+// 	lock(m);
+// 	wait( c, m, 2`s );
+// 	unlock(m);
+// 	printf("T1 wakes\n");
+// 	printf("T1 done\n");
+// }
+
+// void main( T2 & this ) {
+// 	printf("T2 start\n");
+// 	lock(m);
+// 	printf("%d\n", counter(c));
+// 	if(empty(c)) {
+// 		printf("T2 wait\n");
+// 		wait(c,m,12);
+// 	}else{
+// 		printf("%d\n", front(c));
+// 		notify_one(c);
+// 	}
+// 	unlock(m);
+// 	printf("T2 done\n");
+// }
+
+// int main() {
+// 	printf("start\n");
+// 	processor p[2];
+// 	{
+// 		T1 t1;
+// 		T2 t2;
+// 	}
+// 	printf("done\n");
+// }
