Index: src/libcfa/bits/debug.c
===================================================================
--- src/libcfa/bits/debug.c	(revision 35bae5268c7dcbf1d3b046f227bc3ea92f379aef)
+++ src/libcfa/bits/debug.c	(revision 35bae5268c7dcbf1d3b046f227bc3ea92f379aef)
@@ -0,0 +1,88 @@
+//
+// 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.
+//
+// libdebug.c --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu Mar 30 12:30:01 2017
+// Last Modified By :
+// Last Modified On :
+// Update Count     : 0
+//
+
+extern "C" {
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+}
+
+enum { buffer_size = 512 };
+static char buffer[ buffer_size ];
+
+extern "C" {
+
+	void __cfaabi_dbg_bits_write( const char *in_buffer, int len ) {
+		// ensure all data is written
+		for ( int count = 0, retcode; count < len; count += retcode ) {
+			in_buffer += count;
+
+			for ( ;; ) {
+				retcode = write( STDERR_FILENO, in_buffer, len - count );
+
+				// not a timer interrupt ?
+				if ( retcode != -1 || errno != EINTR ) break;
+			}
+
+			if ( retcode == -1 ) _exit( EXIT_FAILURE );
+		}
+	}
+
+	void __cfaabi_dbg_bits_acquire() __attribute__((__weak__)) {}
+	void __cfaabi_dbg_bits_release() __attribute__((__weak__)) {}
+
+	void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
+		va_list args;
+
+		va_start( args, fmt );
+		__cfaabi_dbg_bits_acquire();
+
+		int len = vsnprintf( buffer, buffer_size, fmt, args );
+		__cfaabi_dbg_bits_write( buffer, len );
+
+		__cfaabi_dbg_bits_release();
+		va_end( args );
+	}
+
+	void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
+		va_list args;
+
+		va_start( args, fmt );
+
+		int len = vsnprintf( buffer, buffer_size, fmt, args );
+		__cfaabi_dbg_bits_write( buffer, len );
+
+		va_end( args );
+	}
+
+	void __cfaabi_dbg_bits_print_vararg( const char fmt[], va_list args ) {
+		int len = vsnprintf( buffer, buffer_size, fmt, args );
+		__cfaabi_dbg_bits_write( buffer, len );
+	}
+
+	void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) )) {
+		va_list args;
+
+		va_start( args, fmt );
+
+		int len = vsnprintf( in_buffer, in_buffer_size, fmt, args );
+		__cfaabi_dbg_bits_write( in_buffer, len );
+
+		va_end( args );
+	}
+}
Index: src/libcfa/bits/debug.h
===================================================================
--- src/libcfa/bits/debug.h	(revision 35bae5268c7dcbf1d3b046f227bc3ea92f379aef)
+++ src/libcfa/bits/debug.h	(revision 35bae5268c7dcbf1d3b046f227bc3ea92f379aef)
@@ -0,0 +1,74 @@
+//
+// 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.
+//
+// libdebug.h --
+//
+// Author           : Thierry Delisle
+// Created On       : Mon Nov 28 12:27:26 2016
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Jul 22 10:02:24 2017
+// Update Count     : 1
+//
+
+#pragma once
+
+#ifdef __CFA_DEBUG__
+	#define __cfaabi_dbg_debug_do(...) __VA_ARGS__
+	#define __cfaabi_dbg_no_debug_do(...)
+	#define __cfaabi_dbg_ctx __PRETTY_FUNCTION__
+	#define __cfaabi_dbg_ctx2 , __PRETTY_FUNCTION__
+	#define __cfaabi_dbg_ctx_param const char * caller
+	#define __cfaabi_dbg_ctx_param2 , const char * caller
+#else
+	#define __cfaabi_dbg_debug_do(...)
+	#define __cfaabi_dbg_no_debug_do(...) __VA_ARGS__
+	#define __cfaabi_dbg_ctx
+	#define __cfaabi_dbg_ctx2
+	#define __cfaabi_dbg_ctx_param
+	#define __cfaabi_dbg_ctx_param2
+#endif
+
+#ifdef __cforall
+extern "C" {
+#endif
+	#include <stdarg.h>
+	#include <stdio.h>
+
+      extern void __cfaabi_dbg_bits_write( const char *buffer, int len );
+      extern void __cfaabi_dbg_bits_acquire();
+      extern void __cfaabi_dbg_bits_release();
+      extern void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
+      extern void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
+      extern void __cfaabi_dbg_bits_print_vararg( const char fmt[], va_list arg );
+      extern void __cfaabi_dbg_bits_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) ));
+#ifdef __cforall
+}
+#endif
+
+#ifdef __CFA_DEBUG_PRINT__
+	#define __cfaabi_dbg_write( buffer, len )         __cfaabi_dbg_bits_write( buffer, len )
+	#define __cfaabi_dbg_acquire()                    __cfaabi_dbg_bits_acquire()
+	#define __cfaabi_dbg_release()                    __cfaabi_dbg_bits_release()
+	#define __cfaabi_dbg_print_safe(...)              __cfaabi_dbg_bits_print_safe   (__VA_ARGS__)
+	#define __cfaabi_dbg_print_nolock(...)            __cfaabi_dbg_bits_print_nolock (__VA_ARGS__)
+	#define __cfaabi_dbg_print_buffer(...)            __cfaabi_dbg_bits_print_buffer (__VA_ARGS__)
+	#define __cfaabi_dbg_print_buffer_decl(...)       char __dbg_text[256]; int __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __cfaabi_dbg_bits_write( __dbg_text, __dbg_len );
+	#define __cfaabi_dbg_print_buffer_local(...)      __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __cfaabi_dbg_bits_write( __dbg_text, __dbg_len );
+#else
+	#define __cfaabi_dbg_write(...)               ((void)0)
+	#define __cfaabi_dbg_acquire()                ((void)0)
+	#define __cfaabi_dbg_release()                ((void)0)
+	#define __cfaabi_dbg_print_safe(...)          ((void)0)
+	#define __cfaabi_dbg_print_nolock(...)        ((void)0)
+	#define __cfaabi_dbg_print_buffer(...)        ((void)0)
+	#define __cfaabi_dbg_print_buffer_decl(...)   ((void)0)
+	#define __cfaabi_dbg_print_buffer_local(...)  ((void)0)
+#endif
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: src/libcfa/bits/locks.h
===================================================================
--- src/libcfa/bits/locks.h	(revision 36982fc1f527597d650797d8db4fa9d288e819d9)
+++ src/libcfa/bits/locks.h	(revision 35bae5268c7dcbf1d3b046f227bc3ea92f379aef)
@@ -16,4 +16,5 @@
 #pragma once
 
+#include "bits/debug.h"
 #include "bits/defs.h"
 
