Index: kernel/generic/include/debug.h
===================================================================
--- kernel/generic/include/debug.h	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/include/debug.h	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -55,6 +55,5 @@
 	do { \
 		if (!(expr)) \
-			panic_assert("%s() at %s:%u:\n%s", \
-			    __func__, __FILE__, __LINE__, #expr); \
+			panic_assert("%s", #expr); \
 	} while (0)
 
@@ -73,6 +72,5 @@
 	do { \
 		if (!(expr)) \
-			panic_assert("%s() at %s:%u:\n%s, %s", \
-			    __func__, __FILE__, __LINE__, #expr, msg); \
+			panic_assert("%s, %s", #expr, msg); \
 	} while (0)
 
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/include/proc/thread.h	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -91,23 +91,21 @@
 	
 	/** Function implementing the thread. */
-	void (*thread_code)(void *);
+	void (* thread_code)(void *);
 	/** Argument passed to thread_code() function. */
 	void *thread_arg;
 	
 	/**
-	 * From here, the stored context is restored
-	 * when the thread is scheduled.
+	 * From here, the stored context is restored when the thread is
+	 * scheduled.
 	 */
 	context_t saved_context;
-	
-	/**
-	 * From here, the stored timeout context
-	 * is restored when sleep times out.
+	/**
+	 * From here, the stored timeout context is restored when sleep times
+	 * out.
 	 */
 	context_t sleep_timeout_context;
-	
-	/**
-	 * From here, the stored interruption context
-	 * is restored when sleep is interrupted.
+	/**
+	 * From here, the stored interruption context is restored when sleep is
+	 * interrupted.
 	 */
 	context_t sleep_interruption_context;
@@ -127,5 +125,4 @@
 	 */
 	bool in_copy_from_uspace;
-	
 	/**
 	 * True if this thread is executing copy_to_uspace().
@@ -190,10 +187,4 @@
 	
 #ifdef CONFIG_UDEBUG
-	/**
-	 * If true, the scheduler will print a stack trace
-	 * to the kernel console upon scheduling this thread.
-	 */
-	bool btrace;
-	
 	/** Debugging stuff */
 	udebug_thread_t udebug;
@@ -246,8 +237,4 @@
 extern bool thread_exists(thread_t *);
 
-#ifdef CONFIG_UDEBUG
-extern void thread_stack_trace(thread_id_t);
-#endif
-
 /** Fpu context slab cache. */
 extern slab_cache_t *fpu_context_slab;
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/src/console/cmd.c	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -78,28 +78,25 @@
 static cmd_info_t help_info = {
 	.name = "help",
-	.description = "List supported commands.",
+	.description = "List of supported commands.",
 	.func = cmd_help,
 	.argc = 0
 };
 
-/* Data and methods for 'reboot' command. */
 static int cmd_reboot(cmd_arg_t *argv);
 static cmd_info_t reboot_info = {
 	.name = "reboot",
-	.description = "Reboot system.",
+	.description = "Reboot.",
 	.func = cmd_reboot,
 	.argc = 0
 };
 
-/* Data and methods for 'uptime' command. */
 static int cmd_uptime(cmd_arg_t *argv);
 static cmd_info_t uptime_info = {
 	.name = "uptime",
-	.description = "Show system uptime.",
+	.description = "Print uptime information.",
 	.func = cmd_uptime,
 	.argc = 0
 };
 
-/* Data and methods for 'continue' command. */
 static int cmd_continue(cmd_arg_t *argv);
 static cmd_info_t continue_info = {
@@ -111,6 +108,4 @@
 
 #ifdef CONFIG_TEST
-
-/* Data and methods for 'test' command. */
 static char test_buf[MAX_CMDLINE + 1];
 static int cmd_test(cmd_arg_t *argv);
@@ -124,5 +119,5 @@
 static cmd_info_t test_info = {
 	.name = "test",
-	.description = "<test> List kernel tests or run a test.",
+	.description = "Print list of kernel tests or run a test.",
 	.func = cmd_test,
 	.argc = 1,
@@ -130,5 +125,4 @@
 };
 
-/* Data and methods for 'bench' command. */
 static int cmd_bench(cmd_arg_t *argv);
 static cmd_arg_t bench_argv[] = {
@@ -144,16 +138,15 @@
 static cmd_info_t bench_info = {
 	.name = "bench",
-	.description = "<test> <count> Run kernel test as benchmark.",
+	.description = "Run kernel test as benchmark.",
 	.func = cmd_bench,
 	.argc = 2,
 	.argv = bench_argv
 };
-
-#endif /* CONFIG_TEST */
+#endif
 
 /* Data and methods for 'description' command. */
 static int cmd_desc(cmd_arg_t *argv);
 static void desc_help(void);
-static char desc_buf[MAX_CMDLINE + 1];
+static char desc_buf[MAX_CMDLINE+1];
 static cmd_arg_t desc_argv = {
 	.type = ARG_TYPE_STRING,
@@ -163,5 +156,5 @@
 static cmd_info_t desc_info = {
 	.name = "describe",
-	.description = "<command> Describe specified command.",
+	.description = "Describe specified command.",
 	.help = desc_help,
 	.func = cmd_desc,
@@ -172,5 +165,5 @@
 /* Data and methods for 'symaddr' command. */
 static int cmd_symaddr(cmd_arg_t *argv);
-static char symaddr_buf[MAX_CMDLINE + 1];
+static char symaddr_buf[MAX_CMDLINE+1];
 static cmd_arg_t symaddr_argv = {
 	.type = ARG_TYPE_STRING,
@@ -180,5 +173,5 @@
 static cmd_info_t symaddr_info = {
 	.name = "symaddr",
-	.description = "<symbol> Return symbol address.",
+	.description = "Return symbol address.",
 	.func = cmd_symaddr,
 	.argc = 1,
@@ -186,6 +179,5 @@
 };
 
-/* Data and methods for 'set4' command. */
-static char set_buf[MAX_CMDLINE + 1];
+static char set_buf[MAX_CMDLINE+1];
 static int cmd_set4(cmd_arg_t *argv);
 static cmd_arg_t set4_argv[] = {
@@ -201,5 +193,5 @@
 static cmd_info_t set4_info = {
 	.name = "set4",
-	.description = "<addr> <value> Set 4B memory location to a value.",
+	.description = "set <dest_addr> <value> - 4byte version",
 	.func = cmd_set4,
 	.argc = 2,
@@ -221,5 +213,5 @@
 static cmd_info_t call0_info = {
 	.name = "call0",
-	.description = "<function> Call function().",
+	.description = "call0 <function> -> call function().",
 	.func = cmd_call0,
 	.argc = 1,
@@ -236,5 +228,5 @@
 static cmd_info_t mcall0_info = {
 	.name = "mcall0",
-	.description = "<function> Call function() on each CPU.",
+	.description = "mcall0 <function> -> call function() on each CPU.",
 	.func = cmd_mcall0,
 	.argc = 1,
@@ -258,5 +250,5 @@
 static cmd_info_t call1_info = {
 	.name = "call1",
-	.description = "<function> <arg1> Call function(arg1).",
+	.description = "call1 <function> <arg1> -> call function(arg1).",
 	.func = cmd_call1,
 	.argc = 2,
@@ -285,5 +277,5 @@
 static cmd_info_t call2_info = {
 	.name = "call2",
-	.description = "<function> <arg1> <arg2> Call function(arg1, arg2).",
+	.description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
 	.func = cmd_call2,
 	.argc = 3,
@@ -318,5 +310,5 @@
 static cmd_info_t call3_info = {
 	.name = "call3",
-	.description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).",
+	.description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
 	.func = cmd_call3,
 	.argc = 4,
@@ -348,5 +340,5 @@
 cmd_info_t tlb_info = {
 	.name = "tlb",
-	.description = "Print TLB of the current CPU.",
+	.description = "Print TLB of current processor.",
 	.help = NULL,
 	.func = cmd_tlb,
@@ -385,25 +377,9 @@
 };
 
-#ifdef CONFIG_UDEBUG
-
-/* Data and methods for 'btrace' command */
-static int cmd_btrace(cmd_arg_t *argv);
-static cmd_arg_t btrace_argv = {
-	.type = ARG_TYPE_INT,
-};
-static cmd_info_t btrace_info = {
-	.name = "btrace",
-	.description = "<threadid> Show thread stack trace.",
-	.func = cmd_btrace,
-	.argc = 1,
-	.argv = &btrace_argv
-};
-
-#endif /* CONFIG_UDEBUG */
 
 static int cmd_sched(cmd_arg_t *argv);
 static cmd_info_t sched_info = {
 	.name = "scheduler",
-	.description = "Show scheduler information.",
+	.description = "List all scheduler information.",
 	.func = cmd_sched,
 	.argc = 0
@@ -430,7 +406,33 @@
 static cmd_info_t zones_info = {
 	.name = "zones",
-	.description = "List memory zones.",
+	.description = "List of memory zones.",
 	.func = cmd_zones,
 	.argc = 0
+};
+
+/* Data and methods for 'ipc' command */
+static int cmd_ipc(cmd_arg_t *argv);
+static cmd_arg_t ipc_argv = {
+	.type = ARG_TYPE_INT,
+};
+static cmd_info_t ipc_info = {
+	.name = "ipc",
+	.description = "ipc <taskid> Show IPC information of given task.",
+	.func = cmd_ipc,
+	.argc = 1,
+	.argv = &ipc_argv
+};
+
+/* Data and methods for 'kill' command */
+static int cmd_kill(cmd_arg_t *argv);
+static cmd_arg_t kill_argv = {
+	.type = ARG_TYPE_INT,
+};
+static cmd_info_t kill_info = {
+	.name = "kill",
+	.description = "kill <taskid> Kill a task.",
+	.func = cmd_kill,
+	.argc = 1,
+	.argv = &kill_argv
 };
 
@@ -443,34 +445,8 @@
 static cmd_info_t zone_info = {
 	.name = "zone",
-	.description = "<zone> Show memory zone structure.",
+	.description = "Show memory zone structure.",
 	.func = cmd_zone,
 	.argc = 1,
 	.argv = &zone_argv
-};
-
-/* Data and methods for 'ipc' command */
-static int cmd_ipc(cmd_arg_t *argv);
-static cmd_arg_t ipc_argv = {
-	.type = ARG_TYPE_INT,
-};
-static cmd_info_t ipc_info = {
-	.name = "ipc",
-	.description = "<taskid> Show IPC information of a task.",
-	.func = cmd_ipc,
-	.argc = 1,
-	.argv = &ipc_argv
-};
-
-/* Data and methods for 'kill' command */
-static int cmd_kill(cmd_arg_t *argv);
-static cmd_arg_t kill_argv = {
-	.type = ARG_TYPE_INT,
-};
-static cmd_info_t kill_info = {
-	.name = "kill",
-	.description = "<taskid> Kill a task.",
-	.func = cmd_kill,
-	.argc = 1,
-	.argv = &kill_argv
 };
 
@@ -506,19 +482,19 @@
 	&cpus_info,
 	&desc_info,
+	&reboot_info,
+	&uptime_info,
 	&halt_info,
 	&help_info,
 	&ipc_info,
 	&kill_info,
-	&physmem_info,
-	&reboot_info,
-	&sched_info,
 	&set4_info,
 	&slabs_info,
+	&sysinfo_info,
 	&symaddr_info,
-	&sysinfo_info,
+	&sched_info,
+	&threads_info,
 	&tasks_info,
-	&threads_info,
+	&physmem_info,
 	&tlb_info,
-	&uptime_info,
 	&version_info,
 	&zones_info,
@@ -528,7 +504,4 @@
 	&bench_info,
 #endif
-#ifdef CONFIG_UDEBUG
-	&btrace_info,
-#endif
 	NULL
 };
@@ -557,4 +530,5 @@
 	}
 }
+
 
 /** List supported commands.
@@ -600,4 +574,5 @@
 }
 
+
 /** Reboot the system.
  *
@@ -613,4 +588,5 @@
 	return 1;
 }
+
 
 /** Print system uptime information.
@@ -848,4 +824,5 @@
 }
 
+
 /** Print detailed description of 'describe' command. */
 void desc_help(void)
@@ -934,5 +911,5 @@
  * @return Always 1
  */
-int cmd_slabs(cmd_arg_t *argv)
+int cmd_slabs(cmd_arg_t * argv)
 {
 	slab_print_list();
@@ -946,5 +923,5 @@
  * @return Always 1
  */
-int cmd_sysinfo(cmd_arg_t *argv)
+int cmd_sysinfo(cmd_arg_t * argv)
 {
 	sysinfo_dump(NULL);
@@ -952,5 +929,6 @@
 }
 
-/** Command for listing thread information
+
+/** Command for listings Thread information
  *
  * @param argv Ignored
@@ -970,5 +948,5 @@
 }
 
-/** Command for listing task information
+/** Command for listings Task information
  *
  * @param argv Ignored
@@ -988,76 +966,59 @@
 }
 
-#ifdef CONFIG_UDEBUG
-
-/** Command for printing thread stack trace
+/** Command for listings Thread information
+ *
+ * @param argv Ignores
+ *
+ * @return Always 1
+ */
+int cmd_sched(cmd_arg_t * argv)
+{
+	sched_print_list();
+	return 1;
+}
+
+/** Command for listing memory zones
+ *
+ * @param argv Ignored
+ *
+ * return Always 1
+ */
+int cmd_zones(cmd_arg_t * argv)
+{
+	zones_print_list();
+	return 1;
+}
+
+/** Command for memory zone details
  *
  * @param argv Integer argument from cmdline expected
  *
  * return Always 1
- *
- */
-int cmd_btrace(cmd_arg_t *argv)
-{
-	thread_stack_trace(argv[0].intval);
-	return 1;
-}
-
-#endif /* CONFIG_UDEBUG */
-
-/** Command for printing scheduler information
- *
- * @param argv Ignores
- *
- * @return Always 1
- */
-int cmd_sched(cmd_arg_t *argv)
-{
-	sched_print_list();
-	return 1;
-}
-
-/** Command for listing memory zones
- *
- * @param argv Ignored
+ */
+int cmd_zone(cmd_arg_t * argv)
+{
+	zone_print_one(argv[0].intval);
+	return 1;
+}
+
+/** Command for printing task ipc details
+ *
+ * @param argv Integer argument from cmdline expected
  *
  * return Always 1
  */
-int cmd_zones(cmd_arg_t *argv)
-{
-	zones_print_list();
-	return 1;
-}
-
-/** Command for memory zone details
+int cmd_ipc(cmd_arg_t * argv)
+{
+	ipc_print_task(argv[0].intval);
+	return 1;
+}
+
+/** Command for killing a task
  *
  * @param argv Integer argument from cmdline expected
  *
- * return Always 1
- */
-int cmd_zone(cmd_arg_t *argv)
-{
-	zone_print_one(argv[0].intval);
-	return 1;
-}
-
-/** Command for printing task IPC details
- *
- * @param argv Integer argument from cmdline expected
- *
- * return Always 1
- */
-int cmd_ipc(cmd_arg_t *argv)
-{
-	ipc_print_task(argv[0].intval);
-	return 1;
-}
-
-/** Command for killing a task
- *
- * @param argv Integer argument from cmdline expected
- *
  * return 0 on failure, 1 on success.
  */
-int cmd_kill(cmd_arg_t *argv)
+int cmd_kill(cmd_arg_t * argv)
 {
 	if (task_kill(argv[0].intval) != EOK)
Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/src/proc/scheduler.c	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -62,6 +62,8 @@
 #include <print.h>
 #include <debug.h>
-#include <stacktrace.h>
-
+
+static void before_task_runs(void);
+static void before_thread_runs(void);
+static void after_thread_ran(void);
 static void scheduler_separated_stack(void);
 
@@ -69,5 +71,5 @@
 
 /** Carry out actions before new task runs. */
-static void before_task_runs(void)
+void before_task_runs(void)
 {
 	before_task_runs_arch();
@@ -78,15 +80,14 @@
  * Perform actions that need to be
  * taken before the newly selected
- * thread is passed control.
+ * tread is passed control.
  *
  * THREAD->lock is locked on entry
  *
  */
-static void before_thread_runs(void)
+void before_thread_runs(void)
 {
 	before_thread_runs_arch();
-	
 #ifdef CONFIG_FPU_LAZY
-	if (THREAD == CPU->fpu_owner)
+	if(THREAD == CPU->fpu_owner)
 		fpu_enable();
 	else
@@ -101,16 +102,4 @@
 	}
 #endif
-	
-#ifdef CONFIG_UDEBUG
-	if (THREAD->btrace) {
-		istate_t *istate = THREAD->udebug.uspace_state;
-		if (istate != NULL) {
-			printf("Thread %" PRIu64 " stack trace:\n", THREAD->tid);
-			stack_trace_istate(istate);
-		}
-		
-		THREAD->btrace = false;
-	}
-#endif
 }
 
@@ -124,5 +113,5 @@
  *
  */
-static void after_thread_ran(void)
+void after_thread_ran(void)
 {
 	after_thread_ran_arch();
@@ -402,4 +391,5 @@
 	 * possible destruction should thread_destroy() be called on this or any
 	 * other processor while the scheduler is still using them.
+	 *
 	 */
 	if (old_task)
@@ -427,8 +417,10 @@
 				 * The thread structure is kept allocated until
 				 * somebody calls thread_detach() on it.
+				 *
 				 */
 				if (!irq_spinlock_trylock(&THREAD->join_wq.lock)) {
 					/*
 					 * Avoid deadlock.
+					 *
 					 */
 					irq_spinlock_unlock(&THREAD->lock, false);
@@ -451,4 +443,5 @@
 			/*
 			 * Prefer the thread after it's woken up.
+			 *
 			 */
 			THREAD->priority = -1;
@@ -458,4 +451,5 @@
 			 * waitq_sleep(). Address of wq->lock is kept in
 			 * THREAD->sleep_queue.
+			 *
 			 */
 			irq_spinlock_unlock(&THREAD->sleep_queue->lock, false);
@@ -467,4 +461,5 @@
 			/*
 			 * Entering state is unexpected.
+			 *
 			 */
 			panic("tid%" PRIu64 ": unexpected state %s.",
@@ -485,6 +480,7 @@
 	
 	/*
-	 * If both the old and the new task are the same,
-	 * lots of work is avoided.
+	 * If both the old and the new task are the same, lots of work is
+	 * avoided.
+	 *
 	 */
 	if (TASK != THREAD->task) {
@@ -492,6 +488,7 @@
 		
 		/*
-		 * Note that it is possible for two tasks
-		 * to share one address space.
+		 * Note that it is possible for two tasks to share one address
+		 * space.
+		 (
 		 */
 		if (old_as != new_as) {
@@ -499,4 +496,5 @@
 			 * Both tasks and address spaces are different.
 			 * Replace the old one with the new one.
+			 *
 			 */
 			as_switch(old_as, new_as);
@@ -529,4 +527,5 @@
 	 * necessary, is to be mapped in before_thread_runs(). This
 	 * function must be executed before the switch to the new stack.
+	 *
 	 */
 	before_thread_runs();
@@ -535,4 +534,5 @@
 	 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to
 	 * thread's stack.
+	 *
 	 */
 	the_copy(THE, (the_t *) THREAD->kstack);
@@ -658,4 +658,5 @@
 				/*
 				 * Ready thread on local CPU
+				 *
 				 */
 				
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/src/proc/task.c	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -449,12 +449,10 @@
 static void task_kill_internal(task_t *task)
 {
+	link_t *cur;
+	
+	/*
+	 * Interrupt all threads.
+	 */
 	irq_spinlock_lock(&task->lock, false);
-	irq_spinlock_lock(&threads_lock, false);
-	
-	/*
-	 * Interrupt all threads.
-	 */
-	
-	link_t *cur;
 	for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
 		thread_t *thread = list_get_instance(cur, thread_t, th_link);
@@ -473,5 +471,4 @@
 	}
 	
-	irq_spinlock_unlock(&threads_lock, false);
 	irq_spinlock_unlock(&task->lock, false);
 }
Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/src/proc/thread.c	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -239,5 +239,5 @@
  * Switch thread to the ready state.
  *
- * @param thread Thread to make ready.
+ * @param t Thread to make ready.
  *
  */
@@ -246,5 +246,5 @@
 	irq_spinlock_lock(&thread->lock, true);
 	
-	ASSERT(thread->state != Ready);
+	ASSERT(!(thread->state == Ready));
 	
 	int i = (thread->priority < RQ_COUNT - 1)
@@ -350,6 +350,5 @@
 	
 #ifdef CONFIG_UDEBUG
-	/* Initialize debugging stuff */
-	thread->btrace = false;
+	/* Init debugging stuff */
 	udebug_thread_initialize(&thread->udebug);
 #endif
@@ -536,6 +535,6 @@
 /** Detach thread.
  *
- * Mark the thread as detached. If the thread is already
- * in the Lingering state, deallocate its resources.
+ * Mark the thread as detached, if the thread is already in the Lingering
+ * state, deallocate its resources.
  *
  * @param thread Thread to be detached.
@@ -741,5 +740,5 @@
 	ASSERT(interrupts_disabled());
 	ASSERT(irq_spinlock_locked(&threads_lock));
-	
+
 	thread_iterator_t iterator;
 	
@@ -752,50 +751,4 @@
 }
 
-#ifdef CONFIG_UDEBUG
-
-void thread_stack_trace(thread_id_t thread_id)
-{
-	irq_spinlock_lock(&threads_lock, true);
-	
-	thread_t *thread = thread_find_by_id(thread_id);
-	if (thread == NULL) {
-		printf("No such thread.\n");
-		irq_spinlock_unlock(&threads_lock, true);
-		return;
-	}
-	
-	irq_spinlock_lock(&thread->lock, false);
-	
-	/*
-	 * Schedule a stack trace to be printed
-	 * just before the thread is scheduled next.
-	 *
-	 * If the thread is sleeping then try to interrupt
-	 * the sleep. Any request for printing an uspace stack
-	 * trace from within the kernel should be always
-	 * considered a last resort debugging means, therefore
-	 * forcing the thread's sleep to be interrupted
-	 * is probably justifiable.
-	 */
-	
-	bool sleeping = false;
-	istate_t *istate = thread->udebug.uspace_state;
-	if (istate != NULL) {
-		printf("Scheduling thread stack trace.\n");
-		thread->btrace = true;
-		if (thread->state == Sleeping)
-			sleeping = true;
-	} else
-		printf("Thread interrupt state not available.\n");
-	
-	irq_spinlock_unlock(&thread->lock, false);
-	
-	if (sleeping)
-		waitq_interrupt_sleep(thread);
-	
-	irq_spinlock_unlock(&threads_lock, true);
-}
-
-#endif /* CONFIG_UDEBUG */
 
 /** Process syscall to create new thread.
@@ -840,4 +793,5 @@
 				 * has already been created. We need to undo its
 				 * creation now.
+				 *
 				 */
 				
@@ -861,4 +815,5 @@
 		 * THREAD_B events for threads that already existed
 		 * and could be detected with THREAD_READ before.
+		 *
 		 */
 		udebug_thread_b_event_attach(thread, TASK);
Index: kernel/generic/src/synch/waitq.c
===================================================================
--- kernel/generic/src/synch/waitq.c	(revision 875c629b6e613286c8356c783a344d75acc6f382)
+++ kernel/generic/src/synch/waitq.c	(revision bf75e3cb2c7ba437dce4bc70fc808e165cdb0206)
@@ -127,10 +127,6 @@
 /** Interrupt sleeping thread.
  *
- * This routine attempts to interrupt a thread from its sleep in
- * a waitqueue. If the thread is not found sleeping, no action
- * is taken.
- *
- * The threads_lock must be already held and interrupts must be
- * disabled upon calling this function.
+ * This routine attempts to interrupt a thread from its sleep in a waitqueue.
+ * If the thread is not found sleeping, no action is taken.
  *
  * @param thread Thread to be interrupted.
@@ -142,8 +138,7 @@
 	DEADLOCK_PROBE_INIT(p_wqlock);
 	
-	/*
-	 * The thread is quaranteed to exist because
-	 * threads_lock is held.
-	 */
+	irq_spinlock_lock(&threads_lock, true);
+	if (!thread_exists(thread))
+		goto out;
 	
 grab_locks:
@@ -155,13 +150,14 @@
 			/*
 			 * The sleep cannot be interrupted.
+			 *
 			 */
 			irq_spinlock_unlock(&thread->lock, false);
-			return;
+			goto out;
 		}
 		
 		if (!irq_spinlock_trylock(&wq->lock)) {
-			/* Avoid deadlock */
 			irq_spinlock_unlock(&thread->lock, false);
 			DEADLOCK_PROBE(p_wqlock, DEADLOCK_THRESHOLD);
+			/* Avoid deadlock */
 			goto grab_locks;
 		}
@@ -177,9 +173,11 @@
 		irq_spinlock_unlock(&wq->lock, false);
 	}
-	
 	irq_spinlock_unlock(&thread->lock, false);
 	
 	if (do_wakeup)
 		thread_ready(thread);
+	
+out:
+	irq_spinlock_unlock(&threads_lock, true);
 }
 
@@ -372,4 +370,5 @@
 		 * If the thread was already interrupted,
 		 * don't go to sleep at all.
+		 *
 		 */
 		if (THREAD->interrupted) {
@@ -382,4 +381,5 @@
 		 * Set context that will be restored if the sleep
 		 * of this thread is ever interrupted.
+		 *
 		 */
 		THREAD->sleep_interruptible = true;
