Index: uspace/lib/c/generic/task.c
===================================================================
--- uspace/lib/c/generic/task.c	(revision 5044114fbee4c5e1d76373641fe69c88fb17fa88)
+++ uspace/lib/c/generic/task.c	(revision 3ea98e8e87df9f30c4dc9c7bdd057c3509b893b9)
@@ -128,8 +128,13 @@
  *
  * @return EOK on success, else error code.
+ * @return TODO check this doesn't return EINVAL -- clash with task_wait
  */
 static errno_t task_setup_wait(task_id_t id, task_wait_t *wait)
 {
 	assert(wait->flags);
+	if (wait->flags & TASK_WAIT_BOTH) {
+		wait->flags |= (TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
+	}
+	wait->tid = id;
 	async_exch_t *exch = taskman_exchange_begin();
 	if (exch == NULL)
@@ -391,5 +396,6 @@
  * @param retval Store return value of the task here.
  *
- * @return EOK on success, else error code.
+ * @return EOK on success
+ * @return EINVAL on lost wait TODO other error codes
  */
 errno_t task_wait(task_wait_t *wait, task_exit_t *texit, int *retval)
@@ -397,10 +403,22 @@
 	errno_t rc;
 	async_wait_for(wait->aid, &rc);
-	
-	if (rc == EOK) {
+
+	if (rc == EOK || rc == EINVAL) {
 		if (wait->flags & TASK_WAIT_EXIT && texit)
 			*texit = ipc_get_arg1(wait->result);
 		if (wait->flags & TASK_WAIT_RETVAL && retval)
 			*retval = ipc_get_arg2(wait->result);
+		
+	}
+
+	if (rc == EOK) {
+		/* Is there another wait to be done? Wait for it! */
+		int old_flags = wait->flags;
+		wait->flags = ipc_get_arg3(wait->result);
+		if (wait->flags != 0 && (old_flags & TASK_WAIT_BOTH)) {
+			rc = task_setup_wait(wait->tid, wait);
+		}
+	} else {
+		wait->flags = 0;
 	}
 
Index: uspace/lib/c/include/task.h
===================================================================
--- uspace/lib/c/include/task.h	(revision 5044114fbee4c5e1d76373641fe69c88fb17fa88)
+++ uspace/lib/c/include/task.h	(revision 3ea98e8e87df9f30c4dc9c7bdd057c3509b893b9)
@@ -44,4 +44,5 @@
 #define TASK_WAIT_EXIT   0x1
 #define TASK_WAIT_RETVAL 0x2
+#define TASK_WAIT_BOTH   0x4
 
 typedef struct {
@@ -49,4 +50,5 @@
 	ipc_call_t result;
 	aid_t aid;
+	task_id_t tid;
 } task_wait_t;
 
@@ -54,4 +56,9 @@
 {
 	wait->flags = flags;
+}
+
+static inline int task_wait_get(task_wait_t *wait)
+{
+	return wait->flags;
 }
 
@@ -84,6 +91,4 @@
 
 extern errno_t task_retval(int);
-//TODO
-//extern int task_exit(int);
 
 #endif
