Index: libc/generic/async.c
===================================================================
--- libc/generic/async.c	(revision 07d960a2b9ef20ab87c0d6809d67083c4fa64298)
+++ libc/generic/async.c	(revision 53ca31817fed7f06057f58a16cd05c40de77ea7d)
@@ -61,15 +61,20 @@
  * 2) Multithreaded server application
  * main() {
- *      wait_for_connection(new_connection);
+ *      async_manager();
  * }
  * 
  *
- * new_connection(int connection) {
- *       accept(connection);
- *       msg = get_msg();
- *       handle(msg);
- *       answer(msg);
- *
- *       msg = get_msg();
+ * client_connection(icallid, *icall) {
+ *       if (want_refuse) {
+ *           ipc_answer_fast(icallid, ELIMIT, 0, 0);
+ *           return;
+ *       }
+ *       ipc_answer_fast(icallid, 0, 0, 0);
+ *
+ *       callid = async_get_call(&call);
+ *       handle(callid, call);
+ *       ipc_answer_fast(callid, 1,2,3);
+ *
+ *       callid = async_get_call(&call);
  *       ....
  * }
@@ -105,4 +110,5 @@
 	ipc_callid_t callid;
 	ipc_call_t call;
+	void (*cthread)(ipc_callid_t,ipc_call_t *);
 } connection_t;
 
@@ -226,5 +232,5 @@
 	/* Setup thread local connection pointer */
 	PS_connection = (connection_t *)arg;
-	client_connection(PS_connection->callid, &PS_connection->call);
+	PS_connection->cthread(PS_connection->callid, &PS_connection->call);
 
 	/* Remove myself from connection hash table */
@@ -248,6 +254,13 @@
  * later we can easily do routing of messages to particular
  * threads.
- */
-static void new_connection(ipc_callid_t callid, ipc_call_t *call)
+ *
+ * @param callid Callid of the IPC_M_CONNECT_ME_TO packet
+ * @param call Call data of the opening packet
+ * @param cthread Thread function that should be called upon
+ *                opening the connection
+ * @return New thread id
+ */
+pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call,
+			     void (*cthread)(ipc_callid_t,ipc_call_t *))
 {
 	pstid_t ptid;
@@ -258,5 +271,5 @@
 	if (!conn) {
 		ipc_answer_fast(callid, ENOMEM, 0, 0);
-		return;
+		return NULL;
 	}
 	conn->in_phone_hash = IPC_GET_ARG3(*call);
@@ -266,9 +279,10 @@
 	conn->call = *call;
 	conn->active = 1; /* We will activate it asap */
+	conn->cthread = cthread;
 	list_initialize(&conn->link);
 	if (!conn->ptid) {
 		free(conn);
 		ipc_answer_fast(callid, ENOMEM, 0, 0);
-		return;
+		return NULL;
 	}
 	key = conn->in_phone_hash;
@@ -279,4 +293,6 @@
 
 	psthread_add_ready(conn->ptid);
+
+	return conn->ptid;
 }
 
@@ -292,5 +308,5 @@
 	case IPC_M_CONNECT_ME_TO:
 		/* Open new connection with thread etc. */
-		new_connection(callid, call);
+		async_new_connection(callid, call, client_connection);
 		break;
 	default:
Index: libc/generic/psthread.c
===================================================================
--- libc/generic/psthread.c	(revision 07d960a2b9ef20ab87c0d6809d67083c4fa64298)
+++ libc/generic/psthread.c	(revision 53ca31817fed7f06057f58a16cd05c40de77ea7d)
@@ -36,4 +36,5 @@
 #include <futex.h>
 #include <assert.h>
+#include <async.h>
 
 #ifndef PSTHREAD_INITIAL_STACK_PAGES_NO
@@ -135,5 +136,7 @@
 		goto ret_0;
 	}
-	assert(!(ctype == PS_TO_MANAGER && list_empty(&manager_list)));
+	/* If we are going to manager and none exists, create it */
+	if (ctype == PS_TO_MANAGER && list_empty(&manager_list))
+		async_create_manager();
 
 	pt = __tcb_get()->pst_data;
@@ -251,5 +254,4 @@
 	futex_down(&psthread_futex);
 	if (list_empty(&manager_list)) {
-		printf("No manager found!.\n");
 		futex_up(&psthread_futex);
 		return;
Index: libc/generic/thread.c
===================================================================
--- libc/generic/thread.c	(revision 07d960a2b9ef20ab87c0d6809d67083c4fa64298)
+++ libc/generic/thread.c	(revision 53ca31817fed7f06057f58a16cd05c40de77ea7d)
@@ -92,10 +92,9 @@
 	__tcb_set(pt->tcb);
 	
-	async_create_manager();
-
 	uarg->uspace_thread_function(uarg->uspace_thread_arg);
 	free(uarg->uspace_stack);
 	free(uarg);
 
+	/* If there is a manager, destroy it */
 	async_destroy_manager();
 	psthread_teardown(pt);
Index: libc/include/async.h
===================================================================
--- libc/include/async.h	(revision 07d960a2b9ef20ab87c0d6809d67083c4fa64298)
+++ libc/include/async.h	(revision 53ca31817fed7f06057f58a16cd05c40de77ea7d)
@@ -3,4 +3,5 @@
 
 #include <ipc/ipc.h>
+#include <psthread.h>
 
 int async_manager(void);
@@ -11,4 +12,6 @@
 
 /* Should be defined by application */
+pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call,
+			     void (*cthread)(ipc_callid_t,ipc_call_t *));
 void client_connection(ipc_callid_t callid, ipc_call_t *call) __attribute__((weak));
 
