Index: uspace/lib/c/generic/private/futex.h
===================================================================
--- uspace/lib/c/generic/private/futex.h	(revision 0b5203bfbdafa8ef8abc2bd7521c6fd282f677e9)
+++ uspace/lib/c/generic/private/futex.h	(revision 8a18d5b12d97994512eb8cf90665e94bad8df103)
@@ -46,6 +46,6 @@
 typedef struct futex {
 	volatile atomic_int val;
-	volatile atomic_int alloc_lock;
-	cap_waitq_handle_t whandle;
+	volatile atomic_int lock;
+	volatile cap_waitq_handle_t whandle;
 
 #ifdef CONFIG_DEBUG_FUTEX
@@ -91,4 +91,25 @@
 #endif
 
+static errno_t allocate_waitq(futex_t *futex)
+{
+	int expected = 0;
+	while (!atomic_compare_exchange_weak_explicit(&futex->lock, &expected,
+	    1, memory_order_acquire, memory_order_relaxed))
+		expected = 0;
+
+	if (futex->whandle == CAP_NIL) {
+		errno_t rc = __SYSCALL1(SYS_WAITQ_CREATE,
+		    (sysarg_t) &futex->whandle);
+		if (rc != EOK) {
+			atomic_store_explicit(&futex->lock, 0,
+			    memory_order_release);
+			return rc;
+		}
+	}
+
+	atomic_store_explicit(&futex->lock, 0, memory_order_release);
+	return EOK;
+}
+
 /** Down the futex with timeout, composably.
  *
@@ -111,4 +132,12 @@
 {
 	// TODO: Add tests for this.
+
+	// Preallocate the waitq handle so that we don't need to risk a failure
+	// during wakeup
+	if (futex->whandle == CAP_NIL) {
+		errno_t rc = allocate_waitq(futex);
+		if (rc != EOK)
+			return rc;
+	}
 
 	if (atomic_fetch_sub_explicit(&futex->val, 1, memory_order_acquire) > 0)
@@ -134,22 +163,4 @@
 
 		assert(timeout > 0);
-	}
-
-	if (futex->whandle == CAP_NIL) {
-		while (atomic_exchange_explicit(&futex->alloc_lock, 1,
-		    memory_order_acquire) == 1)
-			;
-		if (futex->whandle == CAP_NIL) {
-			errno_t rc = __SYSCALL1(SYS_WAITQ_CREATE,
-			    (sysarg_t) &futex->whandle);
-			if (rc != EOK) {
-				atomic_store_explicit(&futex->alloc_lock, 0,
-				    memory_order_release);
-				return rc;
-			}
-		}
-
-		atomic_store_explicit(&futex->alloc_lock, 0,
-		    memory_order_release);
 	}
 
Index: uspace/lib/c/generic/thread/futex.c
===================================================================
--- uspace/lib/c/generic/thread/futex.c	(revision 0b5203bfbdafa8ef8abc2bd7521c6fd282f677e9)
+++ uspace/lib/c/generic/thread/futex.c	(revision 8a18d5b12d97994512eb8cf90665e94bad8df103)
@@ -53,5 +53,5 @@
 {
 	atomic_store_explicit(&futex->val, val, memory_order_relaxed);
-	atomic_store_explicit(&futex->alloc_lock, 0, memory_order_relaxed);
+	atomic_store_explicit(&futex->lock, 0, memory_order_relaxed);
 	futex->whandle = CAP_NIL;
 }
