Index: trunk/kernel/kern/process.c
===================================================================
--- trunk/kernel/kern/process.c	(revision 593)
+++ trunk/kernel/kern/process.c	(revision 610)
@@ -95,4 +95,5 @@
                              xptr_t      parent_xp )
 {
+    xptr_t      process_xp;
     cxy_t       parent_cxy;
     process_t * parent_ptr;
@@ -113,4 +114,7 @@
     pid_t       parent_pid;
 
+    // build extended pointer on this reference process
+    process_xp = XPTR( local_cxy , process );
+
     // get parent process cluster and local pointer
     parent_cxy = GET_CXY( parent_xp );
@@ -121,11 +125,12 @@
 
 #if DEBUG_PROCESS_REFERENCE_INIT
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x enter to initalialize process %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , pid , cycle );
-#endif
-
-    // initialize PID, REF_XP, PARENT_XP, and STATE
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] enter to initalialize process %x / cycle %d\n",
+__FUNCTION__, parent_pid, this->trdid, pid, cycle );
+#endif
+
+    // initialize pid, ref_xp, parent_xp, owner_xp, term_state fields
 	process->pid        = pid;
     process->ref_xp     = XPTR( local_cxy , process );
@@ -134,4 +139,8 @@
     process->term_state = 0;
 
+    // initialize VFS root inode and CWD inode
+    process->vfs_root_xp = hal_remote_l64( XPTR( parent_cxy, &parent_ptr->vfs_root_xp ) );
+    process->cwd_xp      = hal_remote_l64( XPTR( parent_cxy, &parent_ptr->cwd_xp ) );
+
     // initialize vmm as empty 
     error = vmm_init( process );
@@ -141,7 +150,7 @@
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x / vmm empty for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , pid, cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] / vmm empty for process %x / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid, cycle );
 #endif
 
@@ -161,7 +170,7 @@
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x / process %x attached to TXT%d / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, txt_id, cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] / process %x attached to TXT%d / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid, txt_id, cycle );
 #endif
         // build path to TXT_RX[i] and TXT_TX[i] chdevs
@@ -170,6 +179,7 @@
 
         // create stdin pseudo file          
-        error = vfs_open( process,
+        error = vfs_open(  process->vfs_root_xp,
                            rx_path,
+                           process_xp,
                            O_RDONLY, 
                            0,                // FIXME chmod
@@ -182,12 +192,13 @@
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x / stdin open for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] / stdin open for process %x / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid, cycle );
 #endif
 
         // create stdout pseudo file          
-        error = vfs_open( process,
+        error = vfs_open(  process->vfs_root_xp,
                            tx_path,
+                           process_xp,
                            O_WRONLY, 
                            0,                // FIXME chmod
@@ -200,12 +211,13 @@
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x / stdout open for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] / stdout open for process %x / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid, cycle );
 #endif
 
         // create stderr pseudo file          
-        error = vfs_open( process,
+        error = vfs_open(  process->vfs_root_xp,
                            tx_path,
+                           process_xp,
                            O_WRONLY, 
                            0,                // FIXME chmod
@@ -218,7 +230,7 @@
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x / stderr open for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] / stderr open for process %x / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid, cycle );
 #endif
 
@@ -247,19 +259,12 @@
     }
 
-    // initialize specific inodes root and cwd
-    process->vfs_root_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
-                                                         &parent_ptr->vfs_root_xp ) );
-    process->vfs_cwd_xp  = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
-                                                         &parent_ptr->vfs_cwd_xp ) );
-    vfs_inode_remote_up( process->vfs_root_xp );
-    vfs_inode_remote_up( process->vfs_cwd_xp );
-
-    remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD );
+    // initialize lock protecting CWD changes
+    remote_busylock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD );
 
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x / set fd_array for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid , cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] / set fd_array for process %x / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid , cycle );
 #endif
 
@@ -300,7 +305,7 @@
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[%s] thread %x in process %x exit for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
+if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
+printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n", 
+__FUNCTION__, parent_pid, this->trdid, pid, cycle );
 #endif
 
@@ -325,9 +330,9 @@
 
 #if DEBUG_PROCESS_COPY_INIT
-thread_t * this = CURRET_THREAD;  
+thread_t * this = CURRENT_THREAD;  
 uint32_t cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_COPY_INIT )
-printk("\n[%s] thread %x in process %x enter for process %x / cycle %d\n",
-__FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle );
+if( DEBUG_PROCESS_COPY_INIT < cycle )
+printk("\n[%s] thread[%x,%x] enter for process %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, local_process->pid, cycle );
 #endif
 
@@ -342,8 +347,8 @@
 	process_fd_init( local_process );
 
-    // reset vfs_root_xp / vfs_bin_xp / vfs_cwd_xp fields
+    // reset vfs_root_xp / vfs_bin_xp / cwd_xp fields
     local_process->vfs_root_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );
     local_process->vfs_bin_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );
-    local_process->vfs_cwd_xp  = XPTR_NULL;
+    local_process->cwd_xp      = XPTR_NULL;
 
     // reset children list root (not used in a process descriptor copy)
@@ -382,7 +387,7 @@
 #if DEBUG_PROCESS_COPY_INIT 
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_COPY_INIT )
-printk("\n[%s] thread %x in process %x exit for process %x / cycle %d\n",
-__FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle );
+if( DEBUG_PROCESS_COPY_INIT < cycle )
+printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, local_process->pid, cycle );
 #endif
 
@@ -406,8 +411,9 @@
 
 #if DEBUG_PROCESS_DESTROY
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_DESTROY )
-printk("\n[%s] thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle );
+if( DEBUG_PROCESS_DESTROY < cycle )
+printk("\n[%s] thread[%x,%x] enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, pid, local_cxy, cycle );
 #endif
 
@@ -446,5 +452,5 @@
 	if( process->vfs_bin_xp  != XPTR_NULL ) vfs_file_count_down( process->vfs_bin_xp );
 	if( process->vfs_root_xp != XPTR_NULL ) vfs_file_count_down( process->vfs_root_xp );
-	if( process->vfs_cwd_xp  != XPTR_NULL ) vfs_file_count_down( process->vfs_cwd_xp );
+	if( process->cwd_xp      != XPTR_NULL ) vfs_file_count_down( process->cwd_xp );
 
     // Destroy VMM
@@ -456,7 +462,7 @@
 #if DEBUG_PROCESS_DESTROY
 cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_DESTROY )
-printk("\n[%s] thread %x in process %x exit / process %x in cluster %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle );
+if( DEBUG_PROCESS_DESTROY < cycle )
+printk("\n[%s] thread[%x,%x] exit / process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, pid, local_cxy, cycle );
 #endif
 
@@ -561,7 +567,4 @@
         process_ptr = GET_PTR( process_xp );
 
-// printk("\n@@@ in %s : process_cxy %x / process_ptr %x / pid %x\n", 
-// __FUNCTION__, process_cxy, process_ptr, hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ) );
-
         if( process_cxy == local_cxy )    // process copy is local
         { 
@@ -652,5 +655,5 @@
 assert( (LPID_FROM_PID( process->pid ) != 0 ), "target process must be an user process" );
 
-    // get target process cluster
+    // get target process owner cluster
     owner_cxy = CXY_FROM_PID( process->pid );
 
@@ -697,5 +700,5 @@
     while( 1 )
     {
-        // exit when all scheduler acknoledges received
+        // exit when all scheduler acknowledges received
         if ( ack_count == 0 ) break;
     
@@ -927,6 +930,8 @@
     uint32_t fd;
 
+    // initialize lock
     remote_queuelock_init( XPTR( local_cxy , &process->fd_array.lock ), LOCK_PROCESS_FDARRAY );
 
+    // initialize number of open files
     process->fd_array.current = 0;
 
@@ -937,6 +942,6 @@
     }
 }
-/////////////////////////////////////////////////
-error_t process_fd_register( process_t * process,
+////////////////////////////////////////////////////
+error_t process_fd_register( xptr_t      process_xp,
                              xptr_t      file_xp,
                              uint32_t  * fdid )
@@ -944,14 +949,28 @@
     bool_t    found;
     uint32_t  id;
-    uint32_t  count;
     xptr_t    xp;
 
     // get reference process cluster and local pointer
-    xptr_t ref_xp = process->ref_xp;
-    process_t * ref_ptr = GET_PTR( ref_xp );
-    cxy_t       ref_cxy = GET_CXY( ref_xp );
+    process_t * process_ptr = GET_PTR( process_xp );
+    cxy_t       process_cxy = GET_CXY( process_xp );
+
+// check client process is reference process
+assert( (process_xp == hal_remote_l64( XPTR( process_cxy , &process_ptr->ref_xp ) ) ),
+"client process must be reference process\n" );
+
+#if DEBUG_PROCESS_FD_REGISTER
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+pid_t      pid   = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid) );
+if( DEBUG_PROCESS_FD_REGISTER < cycle )
+printk("\n[%s] thread[%x,%x] enter for process %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, pid, cycle );
+#endif
+
+    // build extended pointer on lock protecting reference fd_array
+    xptr_t lock_xp = XPTR( process_cxy , &process_ptr->fd_array.lock );
 
     // take lock protecting reference fd_array
-	remote_queuelock_acquire( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
+	remote_queuelock_acquire( lock_xp );
 
     found   = false;
@@ -959,18 +978,10 @@
     for ( id = 0; id < CONFIG_PROCESS_FILE_MAX_NR ; id++ )
     {
-        xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) );
+        xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[id] ) );
         if ( xp == XPTR_NULL )
         {
             // update reference fd_array
-            hal_remote_s64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp );
-	        count = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ) + 1;
-            hal_remote_s32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , count );
-
-            // update local fd_array copy if required
-            if( ref_cxy != local_cxy )
-            {
-                process->fd_array.array[id] = file_xp;
-                process->fd_array.current   = count;
-            }
+            hal_remote_s64( XPTR( process_cxy , &process_ptr->fd_array.array[id] ) , file_xp );
+	        hal_remote_atomic_add( XPTR( process_cxy , &process_ptr->fd_array.current ) , 1 );
 
             // exit
@@ -981,10 +992,18 @@
     }
 
-    // release lock protecting reference fd_array
-	remote_queuelock_release( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
+    // release lock protecting fd_array
+	remote_queuelock_release( lock_xp );
+
+#if DEBUG_PROCESS_FD_REGISTER
+cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_PROCESS_FD_REGISTER < cycle )
+printk("\n[%s] thread[%x,%x] exit for process %x / fdid %d / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, pid, id, cycle );
+#endif
 
     if ( !found ) return -1;
     else          return 0;
-}
+
+}  // end process_fd_register()
 
 ////////////////////////////////////////////////
@@ -1119,9 +1138,4 @@
         // returns trdid
         *trdid = TRDID( local_cxy , ltid );
-
-// if( LPID_FROM_PID( process->pid ) == 0 )
-// printk("\n@@@ %s : allocate ltid %d for a thread %s in cluster %x\n",
-// __FUNCTION__, ltid, thread_type_str( thread->type), local_cxy );
-
     }
 
@@ -1158,8 +1172,4 @@
     process->th_tbl[ltid] = NULL;
     process->th_nr = count-1;
-
-// if( LPID_FROM_PID( process->pid ) == 0 )
-// printk("\n@@@ %s : release ltid %d for a thread %s in cluster %x\n",
-// __FUNCTION__, ltid, thread_type_str( thread->type), local_cxy );
 
     // release lock protecting th_tbl
@@ -1363,4 +1373,5 @@
     process_t      * process;                 // local pointer on this process
     pid_t            pid;                     // this process identifier
+    xptr_t           ref_xp;                  // reference process for this process
 	error_t          error;                   // value returned by called functions
     char           * path;                    // path to .elf file
@@ -1370,8 +1381,9 @@
     char          ** args_pointers;           // array of pointers on main thread arguments
 
-    // get thread, process & PID 
+    // get thread, process, pid and ref_xp 
     thread  = CURRENT_THREAD;
     process = thread->process;
     pid     = process->pid;
+    ref_xp  = process->ref_xp;
 
 	// get relevant infos from exec_info
@@ -1390,6 +1402,7 @@
     file_xp = XPTR_NULL;
     file_id = 0xFFFFFFFF;
-	error   = vfs_open( process,
+	error   = vfs_open( process->vfs_root_xp,
 	                    path,
+                        ref_xp,
 	                    O_RDONLY,
 	                    0,
@@ -1543,5 +1556,5 @@
 #endif
 
-}  // end process_zero_init()
+}  // end process_zero_create()
 
 ////////////////////////////////
@@ -1558,8 +1571,9 @@
 
 #if DEBUG_PROCESS_INIT_CREATE
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x enter / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
+printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, cycle );
 #endif
 
@@ -1571,4 +1585,8 @@
 "no memory for process descriptor in cluster %x\n", local_cxy  );
 
+    // set the CWD and VFS_ROOT fields in process descriptor
+    process->cwd_xp      = process_zero.vfs_root_xp;
+    process->vfs_root_xp = process_zero.vfs_root_xp;
+
     // get PID from local cluster
     error = cluster_pid_alloc( process , &pid );
@@ -1589,6 +1607,6 @@
 #if(DEBUG_PROCESS_INIT_CREATE & 1)
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x initialized process descriptor\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+printk("\n[%s] thread[%x,%x] initialized process descriptor\n",
+__FUNCTION__, this->process->pid, this->trdid );
 #endif
 
@@ -1596,6 +1614,7 @@
     file_xp = XPTR_NULL;
     file_id = -1;
-	error   = vfs_open( process,
+	error   = vfs_open( process->vfs_root_xp,
 	                    CONFIG_PROCESS_INIT_PATH,
+                        XPTR( local_cxy , process ),
 	                    O_RDONLY,
 	                    0,
@@ -1608,6 +1627,6 @@
 #if(DEBUG_PROCESS_INIT_CREATE & 1)
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x open .elf file decriptor\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+printk("\n[%s] thread[%x,%x] open .elf file decriptor\n",
+__FUNCTION__, this->process->pid, this->trdid );
 #endif
 
@@ -1621,6 +1640,6 @@
 #if(DEBUG_PROCESS_INIT_CREATE & 1)
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x registered code/data vsegs in VMM\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+printk("\n[%s] thread[%x,%x] registered code/data vsegs in VMM\n",
+__FUNCTION__, this->process->pid, this->trdid );
 #endif
 
@@ -1641,6 +1660,6 @@
 #if(DEBUG_PROCESS_INIT_CREATE & 1)
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x registered init process in parent\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+printk("\n[%s] thread[%x,%x] registered init process in parent\n",
+__FUNCTION__, this->process->pid, this->trdid );
 #endif
 
@@ -1668,6 +1687,6 @@
 #if(DEBUG_PROCESS_INIT_CREATE & 1)
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x created main thread\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+printk("\n[%s] thread[%x,%x] created main thread\n",
+__FUNCTION__, this->process->pid, this->trdid );
 #endif
 
@@ -1680,6 +1699,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_INIT_CREATE < cycle )
-printk("\n[%s] thread %x in process %x exit / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
+printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, cycle );
 #endif
 
@@ -1865,9 +1884,9 @@
 
 #if DEBUG_PROCESS_TXT
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_TXT < cycle )
-printk("\n[%s] thread %x in process %x attached process %x to TXT %d / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
-process->pid, txt_id , cycle );
+printk("\n[%s] thread[%x,%x] attached process %x to TXT %d / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid, txt_id , cycle );
 #endif
 
@@ -1919,10 +1938,10 @@
 
 #if DEBUG_PROCESS_TXT
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle  = (uint32_t)hal_get_cycles();
 uint32_t txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
 if( DEBUG_PROCESS_TXT < cycle )
-printk("\n[%s] thread %x in process %x detached process %x from TXT %d / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
-process_pid, txt_id, cycle );
+printk("\n[%s] thread[%x,%x] detached process %x from TXT %d / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process_pid, txt_id, cycle );
 #endif
 
@@ -1961,9 +1980,10 @@
 
 #if DEBUG_PROCESS_TXT
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle  = (uint32_t)hal_get_cycles();
 uint32_t txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) );
 if( DEBUG_PROCESS_TXT < cycle )
-printk("\n[%s] thread %x in process %x give TXT %d to process %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, process_pid, cycle );
+printk("\n[%s] thread[%x,%x] give TXT %d to process %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, txt_id, process_pid, cycle );
 #endif
 
@@ -1990,5 +2010,6 @@
 
 #if DEBUG_PROCESS_TXT
-uint32_t cycle;
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle;
 #endif
 
@@ -2042,9 +2063,9 @@
 
 #if DEBUG_PROCESS_TXT
-cycle   = (uint32_t)hal_get_cycles();
+cycle = (uint32_t)hal_get_cycles();
 uint32_t ksh_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
 if( DEBUG_PROCESS_TXT < cycle )
-printk("\n[%s] thread %x in process %x release TXT %d to KSH %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, ksh_pid, cycle );
+printk("\n[%s] thread[%x,%x] release TXT %d to KSH %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, txt_id, ksh_pid, cycle );
 process_txt_display( txt_id );
 #endif
@@ -2079,9 +2100,9 @@
 
 #if DEBUG_PROCESS_TXT
-cycle   = (uint32_t)hal_get_cycles();
+cycle  = (uint32_t)hal_get_cycles();
 uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
 if( DEBUG_PROCESS_TXT < cycle )
-printk("\n[%s] thread %x in process %x release TXT %d to process %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, new_pid, cycle );
+printk("\n[%s] thread[%x,%x] release TXT %d to process %x / cycle %d\n",
+__FUNCTION__,this->process->pid, this->trdid, txt_id, new_pid, cycle );
 process_txt_display( txt_id );
 #endif
@@ -2099,6 +2120,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_TXT < cycle )
-printk("\n[%s] thread %x in process %x release TXT %d to nobody / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, cycle );
+printk("\n[%s] thread[%x,%x] release TXT %d to nobody / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, txt_id, cycle );
 process_txt_display( txt_id );
 #endif
@@ -2113,5 +2134,5 @@
 if( DEBUG_PROCESS_TXT < cycle )
 printk("\n[%s] thread %x in process %d does nothing (not TXT owner) / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, process_pid, cycle );
+__FUNCTION__, this->trdid, process_pid, cycle );
 process_txt_display( txt_id );
 #endif
