Index: trunk/kernel/kern/scheduler.c
===================================================================
--- trunk/kernel/kern/scheduler.c	(revision 409)
+++ trunk/kernel/kern/scheduler.c	(revision 416)
@@ -58,5 +58,5 @@
     list_root_init( &sched->k_root );
 
-    sched->sig_pending    = false;            // no pending signal
+    sched->req_ack_pending = false;           // no pending request
 
 }  // end sched_init()
@@ -89,31 +89,4 @@
 
 }  // end sched_register_thread()
-
-/////////////////////////////////////////////
-void sched_remove_thread( thread_t * thread )
-{
-    scheduler_t * sched = &thread->core->scheduler;
-    thread_type_t type  = thread->type;
-
-    // take lock protecting sheduler lists
-    spinlock_lock( &sched->lock );
-
-    if( type == THREAD_USER )
-    {
-        list_unlink( &thread->sched_list );
-        sched->u_threads_nr--;
-        if( sched->u_threads_nr == 0 ) sched->u_last = NULL;
-    }
-    else // kernel thread
-    {
-        list_unlink( &thread->sched_list );
-        sched->k_threads_nr--;
-        if( sched->k_threads_nr == 0 ) sched->k_last = NULL;
-    }
-
-    // release lock 
-    spinlock_unlock( &sched->lock );
-
-}  // end sched_remove_thread()
 
 //////////////////////////////////////////////
@@ -203,10 +176,13 @@
 }  // end sched_select()
 
-//////////////////////////////////////////
-void sched_handle_signals( core_t * core )
+///////////////////////////////////////////
+void sched_handle_requests( core_t * core )
 {
     list_entry_t * iter;
     thread_t     * thread;
 
+// printk("\n@@@ %s : current thread %x enter at cycle %d\n",
+// __FUNCTION__ , CURRENT_THREAD , hal_time_stamp() );
+
     scheduler_t  * sched = &core->scheduler;
 
@@ -214,16 +190,50 @@
     spinlock_lock( &sched->lock );
 
-    // handle user threads
+    // scan all user threads
     LIST_FOREACH( &sched->u_root , iter )
     {
         thread = LIST_ELEMENT( iter , thread_t , sched_list );
 
-        if( thread->flags & THREAD_FLAG_SIGNAL )  // thread has signal
-        {
-            // decrement response counter to acknowledge signal
-            hal_atomic_add( thread->sig_rsp_count , -1 );
-
-            // reset signal
-            thread_reset_signal( thread );
+        // handle REQ_ACK 
+        if( thread->flags & THREAD_FLAG_REQ_ACK )
+        {
+            // check thread blocked
+            assert( (thread->blocked & THREAD_BLOCKED_GLOBAL) , 
+            __FUNCTION__ , "thread not blocked" );
+ 
+            // decrement response counter
+            hal_atomic_add( thread->ack_rsp_count , -1 );
+
+            // reset REQ_ACK in thread descriptor
+            thread_reset_req_ack( thread );
+        }
+
+        // handle REQ_DELETE
+        if( thread->flags & THREAD_FLAG_REQ_DELETE )
+        {
+
+sched_dmsg("\n[DBG] %s : current thread %x delete thread %x at cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , thread , hal_time_stamp() );
+
+	        // release FPU if required
+	        if( thread->core->fpu_owner == thread )  thread->core->fpu_owner = NULL;
+
+            // detach thread from parent if attached
+            if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 
+            thread_child_parent_unlink( thread->parent , XPTR( local_cxy , thread ) );
+
+            // detach thread from process
+            process_remove_thread( thread );
+
+            // remove thread from scheduler
+            list_unlink( &thread->sched_list );
+            sched->u_threads_nr--;
+            if( sched->u_threads_nr == 0 ) sched->u_last = NULL;
+
+            // release memory allocated to thread
+            thread_destroy( thread );
+
+            // destroy process descriptor if no more threads
+            if (thread->process->th_nr == 0) process_destroy( thread->process );
         }
     }
@@ -232,5 +242,8 @@
     spinlock_unlock( &sched->lock );
 
-} // end sched_handle_signals()
+// printk("\n@@@ %s : current thread %x exit at cycle %d\n",
+// __FUNCTION__ , CURRENT_THREAD , hal_time_stamp() );
+
+} // end sched_handle_requests()
 
 ////////////////////////////////
@@ -305,6 +318,6 @@
     }
 
-    // handle signals for all threads executing on this core.
-    sched_handle_signals( core );
+    // handle pending requests for all threads executing on this core.
+    sched_handle_requests( core );
 
     // exit critical section / restore SR from next thread context
@@ -354,13 +367,13 @@
         if (thread->type == THREAD_DEV) 
         {
-            nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X / %s\n",
+            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X / %s\n",
             thread_type_str( thread->type ), thread->process->pid, thread->trdid,
-            thread, thread->blocked , thread->chdev->name );
+            thread, thread->blocked, thread->flags, thread->chdev->name );
         }
         else
         {
-            nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n",
+            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X \n",
             thread_type_str( thread->type ), thread->process->pid, thread->trdid,
-            thread, thread->blocked );
+            thread, thread->blocked, thread->flags  );
         }
     }
@@ -370,7 +383,7 @@
     {
         thread = LIST_ELEMENT( iter , thread_t , sched_list );
-        nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n",
+        nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n",
         thread_type_str( thread->type ), thread->process->pid, thread->trdid,
-        thread, thread->blocked );
+        thread, thread->blocked, thread->flags );
     }
 
