Index: trunk/kernel/kern/thread.c
===================================================================
--- trunk/kernel/kern/thread.c	(revision 440)
+++ trunk/kernel/kern/thread.c	(revision 443)
@@ -142,4 +142,11 @@
 	cluster_t    * local_cluster = LOCAL_CLUSTER;
 
+#if DEBUG_THREAD_USER_INIT
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_THREAD_USER_INIT < cycle )
+printk("\n[DBG] %s : thread %x enter to init thread %x in process %x / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD, thread, process->pid , cycle );
+#endif
+
     // register new thread in process descriptor, and get a TRDID
     error = process_register_thread( process, thread , &trdid );
@@ -196,5 +203,6 @@
 	thread->signature = THREAD_SIGNATURE;
 
-    // FIXME call hal_thread_init() function to initialise the save_sr field
+    // FIXME define and call an architecture specific hal_thread_init()
+    // function to initialise the save_sr field
     thread->save_sr = 0xFF13;
 
@@ -204,4 +212,11 @@
 	// update DQDT 
     dqdt_update_threads( 1 );
+
+#if DEBUG_THREAD_USER_INIT
+cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_THREAD_USER_INIT < cycle )
+printk("\n[DBG] %s : thread %x exit  after init of thread %x in process %x / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD, thread, process->pid , cycle );
+#endif
 
 	return 0;
@@ -227,6 +242,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_THREAD_USER_CREATE < cycle )
-printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, pid , cycle );
+printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD, pid , local_cxy , cycle );
 #endif
 
@@ -240,4 +255,10 @@
         return ENOMEM;
     }
+
+#if( DEBUG_THREAD_USER_CREATE & 1)
+if( DEBUG_THREAD_USER_CREATE < cycle )
+printk("\n[DBG] %s : process descriptor = %x for process %x in cluster %x\n",
+__FUNCTION__, process , pid , local_cxy );
+#endif
 
     // select a target core in local cluster
@@ -256,4 +277,10 @@
         core_lid = cluster_select_local_core();
     }
+
+#if( DEBUG_THREAD_USER_CREATE & 1)
+if( DEBUG_THREAD_USER_CREATE < cycle )
+printk("\n[DBG] %s : core[%x,%d] selected\n",
+__FUNCTION__, local_cxy , core_lid );
+#endif
 
     // allocate a stack from local VMM
@@ -282,4 +309,10 @@
         return ENOMEM;
     }
+
+#if( DEBUG_THREAD_USER_CREATE & 1)
+if( DEBUG_THREAD_USER_CREATE < cycle )
+printk("\n[DBG] %s : thread descriptor %x allocated\n",
+__FUNCTION__, thread );
+#endif
 
     // initialize thread descriptor
@@ -300,4 +333,10 @@
     }
 
+#if( DEBUG_THREAD_USER_CREATE & 1)
+if( DEBUG_THREAD_USER_CREATE < cycle )
+printk("\n[DBG] %s : thread descriptor %x initialised / trdid = %x\n",
+__FUNCTION__, thread , thread->trdid );
+#endif
+
     // set DETACHED flag if required
     if( attr->attributes & PT_ATTR_DETACH ) 
@@ -327,6 +366,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_THREAD_USER_CREATE < cycle )
-printk("\n[DBG] %s : thread %x exit / process %x / new_thread %x / core %d / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, pid, thread, core_lid, cycle );
+printk("\n[DBG] %s : thread %x exit / new_thread %x in process %x / core %d / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD, thread->trdid , pid , core_lid, cycle );
 #endif
 
@@ -602,7 +641,8 @@
 // has been released, using a cache of mmap requests. [AG]
 ///////////////////////////////////////////////////////////////////////////////////////
-void thread_destroy( thread_t * thread )
+bool_t thread_destroy( thread_t * thread )
 {
     reg_t        save_sr;
+    bool_t       last_thread;
 
     process_t  * process    = thread->process;
@@ -616,7 +656,9 @@
 #endif
 
-    assert( (thread->local_locks == 0) , __FUNCTION__ , "all local locks not released" );
-
-    assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" );
+    assert( (thread->local_locks == 0) , __FUNCTION__ , 
+    "local lock not released for thread %x in process %x", thread->trdid, process->pid );
+
+    assert( (thread->remote_locks == 0) , __FUNCTION__ , 
+    "remote lock not released for thread %x in process %x", thread->trdid, process->pid );
 
     // update intrumentation values
@@ -637,5 +679,5 @@
 
     // remove thread from process th_tbl[]
-    process_remove_thread( thread );
+    last_thread = process_remove_thread( thread );
 	
     // update DQDT
@@ -654,4 +696,6 @@
 __FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle );
 #endif
+
+    return last_thread;
 
 }   // end thread_destroy()
@@ -1092,5 +1136,6 @@
         hal_enable_irq( NULL );
 
-        if( CONFIG_THREAD_IDLE_MODE_SLEEP ) // force core to low-power mode
+        // force core to low-power mode (optional)
+        if( CONFIG_THREAD_IDLE_MODE_SLEEP ) 
         {
 
@@ -1113,8 +1158,7 @@
 
         }
-        else                                // search a runable thread
-        {
-            sched_yield( "IDLE" );
-        }
+
+        // search a runable thread
+        sched_yield( "IDLE" );
     }
 }  // end thread_idle()
