Index: src/libcfa/bits/locks.h
===================================================================
--- src/libcfa/bits/locks.h	(revision 0c674e80fb16ad200b53123b9c7451e3a60db3ae)
+++ src/libcfa/bits/locks.h	(revision ea8b2f7e16005c4ecdb2566b748c8eb02f60f32b)
@@ -18,4 +18,11 @@
 #include "bits/debug.h"
 #include "bits/defs.h"
+#include <assert.h>
+
+#ifdef __cforall
+	extern "C" {
+		#include <pthread.h>
+	}
+#endif
 
 // pause to prevent excess processor bus usage
@@ -112,3 +119,45 @@
 		__atomic_clear( &this.lock, __ATOMIC_RELEASE );
 	}
+
+
+	#ifdef __CFA_WITH_VERIFY__
+		extern bool __cfaabi_dbg_in_kernel();
+	#endif
+
+	struct __bin_sem_t {
+		int_fast8_t     counter;
+		pthread_mutex_t lock;
+		pthread_cond_t  cond;
+	};
+
+	static inline void ?{}(__bin_sem_t & this) with( this ) {
+		counter = 0;
+		pthread_mutex_init(&lock, NULL);
+		pthread_cond_init (&cond, NULL);
+	}
+
+	static inline void ^?{}(__bin_sem_t & this) with( this ) {
+		pthread_mutex_destroy(&lock);
+		pthread_cond_destroy (&cond);
+	}
+
+	static inline void wait(__bin_sem_t & this) with( this ) {
+		verify(__cfaabi_dbg_in_kernel());
+		pthread_mutex_lock(&lock);
+		if(counter != 0) {   // this must be a loop, not if!
+			pthread_cond_wait(&cond, &lock);
+		}
+		counter = 1;
+		pthread_mutex_unlock(&lock);
+	}
+
+	static inline void post(__bin_sem_t & this) with( this ) {
+		verify(__cfaabi_dbg_in_kernel());
+		pthread_mutex_lock(&lock);
+		bool needs_signal = counter == 0;
+		counter = 1;
+		pthread_mutex_unlock(&lock);
+		if (!needs_signal)
+			pthread_cond_signal(&cond);
+		}
 #endif
