Index: kernel/generic/include/proc/task.h
===================================================================
--- kernel/generic/include/proc/task.h	(revision d84319865c1131f37cbdba6ba952c5d38c735d0d)
+++ kernel/generic/include/proc/task.h	(revision cb4afd8bbf37def6ce88be49db41f1a2fd01c053)
@@ -65,6 +65,4 @@
 	
 	char *name;
-	/** Pointer to the main thread. */
-	struct thread *main_thread;
 	/** List of threads contained in this task. */
 	link_t th_head;
@@ -76,8 +74,8 @@
 	context_id_t context;	
 
-	/** If this is true, new threads can become part of the task. */
-	bool accept_new_threads;
 	/** Number of references (i.e. threads). */
-	count_t refcount;	
+	atomic_t refcount;
+	/** Number of threads that haven't exited yet. */
+	atomic_t lifecount;
 
 	/** Task capabilities. */
@@ -123,5 +121,4 @@
 extern cap_t cap_get(task_t *t);
 
-
 #ifndef task_create_arch
 extern void task_create_arch(task_t *t);
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision d84319865c1131f37cbdba6ba952c5d38c735d0d)
+++ kernel/generic/include/proc/thread.h	(revision cb4afd8bbf37def6ce88be49db41f1a2fd01c053)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2001-2007 Jakub Jermar
  * All rights reserved.
  *
@@ -41,4 +41,5 @@
 #include <cpu.h>
 #include <synch/rwlock.h>
+#include <synch/spinlock.h>
 #include <adt/btree.h>
 #include <mm/slab.h>
@@ -81,14 +82,7 @@
 	/** After a thread calls thread_exit(), it is put into Exiting state. */
 	Exiting,
-	/** Threads that were not detached but exited are in the Undead state. */
-	Undead
+	/** Threads that were not detached but exited are in the JoinMe state. */
+	JoinMe
 } state_t;
-
-/** Join types. */
-typedef enum {
-	None,
-	TaskClnp,	/**< The thread will be joined by ktaskclnp thread. */
-	TaskGC		/**< The thread will be joined by ktaskgc thread. */
-} thread_join_type_t;
 
 /** Thread structure. There is one per thread. */
@@ -153,10 +147,10 @@
 	bool interrupted;			
 	
-	/** Who joinins the thread. */
-	thread_join_type_t join_type;
 	/** If true, thread_join_timeout() cannot be used on this thread. */
 	bool detached;
 	/** Waitq for thread_join_timeout(). */
 	waitq_t join_wq;
+	/** Link used in the joiner_head list. */
+	link_t joiner_link;
 
 	fpu_context_t *saved_fpu_context;
