Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 278b4a3073e1c10f12dee772798386520fad774a)
+++ kernel/generic/src/proc/thread.c	(revision 7ed853050d7b8bf31fc2d7176881bf29f3027d43)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2010 Jakub Jermar
  * All rights reserved.
  *
@@ -409,9 +409,7 @@
 
 	/*
-	 * t is guaranteed to be the very last thread of its task.
-	 * It is safe to destroy the task.
+	 * Drop the reference to the containing task.
 	 */
-	if (atomic_predec(&t->task->refcount) == 0)
-		task_destroy(t->task);
+	task_release(t->task);
 	
 	slab_free(thread_slab, t);
@@ -436,5 +434,6 @@
 	spinlock_lock(&task->lock);
 
-	atomic_inc(&task->refcount);
+	/* Hold a reference to the task. */
+	task_hold(task);
 
 	/* Must not count kbox thread into lifecount */
