Index: uspace/app/gfxdemo/gfxdemo.c
===================================================================
--- uspace/app/gfxdemo/gfxdemo.c	(revision 489f4053679ae40a64fe6498ce573c3cf921b7ce)
+++ uspace/app/gfxdemo/gfxdemo.c	(revision 9adae25d90fa489920cc8bbfbb3d7fa7b4bf3b75)
@@ -51,4 +51,5 @@
 #include <ui/window.h>
 #include <ui/wdecor.h>
+#include "gfxdemo.h"
 
 static void wnd_close_event(void *);
@@ -77,4 +78,5 @@
 static gfx_coord_t vpad;
 static console_ctrl_t *con = NULL;
+static ui_t *ui;
 
 /** Determine if we are running in text mode.
@@ -100,4 +102,6 @@
 	cons_event_t cevent;
 
+	if (ui != NULL)
+		ui_unlock(ui);
 	fibril_mutex_lock(&quit_lock);
 	if (!quit) {
@@ -120,4 +124,6 @@
 	}
 	fibril_mutex_unlock(&quit_lock);
+	if (ui != NULL)
+		ui_lock(ui);
 }
 
@@ -1099,8 +1105,19 @@
 }
 
+static errno_t demo_ui_fibril(void *arg)
+{
+	demo_ui_args_t *args = (demo_ui_args_t *)arg;
+	errno_t rc;
+
+	ui_lock(args->ui);
+	rc = demo_loop(args->gc, args->dims.x, args->dims.y);
+	ui_unlock(args->ui);
+	ui_quit(args->ui);
+	return rc;
+}
+
 /** Run demo on UI. */
 static errno_t demo_ui(const char *display_spec)
 {
-	ui_t *ui = NULL;
 	ui_wnd_params_t params;
 	ui_window_t *window = NULL;
@@ -1111,4 +1128,6 @@
 	gfx_rect_t ui_rect;
 	gfx_coord2_t dims;
+	demo_ui_args_t args;
+	fid_t fid;
 	errno_t rc;
 
@@ -1169,8 +1188,17 @@
 		task_retval(0);
 
-	rc = demo_loop(gc, dims.x, dims.y);
-	if (rc != EOK)
-		goto error;
-
+	args.gc = gc;
+	args.dims = dims;
+	args.ui = ui;
+
+	fid = fibril_create(demo_ui_fibril, (void *)&args);
+	if (fid == 0) {
+		rc = ENOMEM;
+		goto error;
+	}
+
+	fibril_add_ready(fid);
+
+	ui_run(ui);
 	ui_window_destroy(window);
 	ui_destroy(ui);
