Index: soft/giet_vm/sort/main.c
===================================================================
--- soft/giet_vm/sort/main.c	(revision 258)
+++ soft/giet_vm/sort/main.c	(revision 269)
@@ -31,7 +31,4 @@
 //            processor id and the first processor must have id 0.
 //
-//      TODO: Replace processor id based identification mechanism by one based
-//            on thread id
-//
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -39,5 +36,4 @@
 #include "hard_config.h"
 #include "barrier.h"
-#include "spin_lock.h"
 
 //////////////////////////////////////////////////////////////////////////
@@ -60,14 +56,6 @@
 
 #if (VERBOSE == 1)
-#   if (NB_TTY_CHANNELS > 1)
-#       define printf(...)     giet_tty_printf(__VA_ARGS__)
-#       define puts(...)       giet_tty_puts(__VA_ARGS__)
-
-#   else    // NB_TTY_CHANNELS == 0
-#       define printf(...) \
-        lock_acquire(&tty_lock); \
-        giet_tty_printf(__VA_ARGS__); \
-        lock_release(&tty_lock);  
-#   endif
+#   define printf(...)     giet_tty_printf(__VA_ARGS__)
+#   define puts(...)       giet_tty_puts(__VA_ARGS__)
 #else       // VERBOSE == 0
 #   define printf(...)
@@ -75,5 +63,5 @@
 #endif
 
-#define task0_printf(...) if(procid() == 0) giet_tty_printf(__VA_ARGS__)
+#define task0_printf(...) if(thread_id == 0) giet_tty_printf(__VA_ARGS__)
 
 #define exit    giet_exit
@@ -104,51 +92,39 @@
 
 giet_barrier_t barrier[8];
-giet_lock_t tty_lock;
 
 __attribute__ ((constructor)) void sort()
 {
-    int proc_id = procid();
+    int thread_id = giet_thread_id();
+
     int * src_array;
     int * dst_array;
     int i;
 
-    task0_printf("Starting SORT application\n");
+    task0_printf("[ Thread 0 ] Starting SORT application\n");
+
+    ///////////////////////////
+    // Barriers Initialization
+
+    for (i = 0; i < __builtin_ctz(NPROCS); i++)
+    {
+        barrier_init(&barrier[i], NPROCS >> i);
+    }
 
     ////////////////////////
     // Array Initialization
 
-    for (i = IPP * proc_id; i < IPP * (proc_id + 1); i++)
+    for (i = IPP * thread_id; i < IPP * (thread_id + 1); i++)
     {
         array0[i] = rand();
     }
-
-    ///////////////////////////
-    // Barriers Initialization
-
-    while((proc_id != 0) && (init_ok == 0));
-
-    if (proc_id == 0)
-    {
-        for (i = 0; i < __builtin_ctz(NPROCS); i++)
-        {
-            task0_printf("Initializing barrier %d with %d\n", i, NPROCS >> i);
-            barrier_init(&barrier[i], NPROCS >> i);
-        }
-
-        asm volatile ("sync");
-        init_ok = 1;
-    }
-
-    asm volatile ("sync");
-    barrier_wait(&barrier[0]);
 
     ///////////////////////////////////
     // Parallel sort of array elements
 
-    printf("Proc %d Stage 0: Processor Sorting...\n\r", proc_id);
-
-    bubbleSort(array0, IPP, IPP * proc_id);
-
-    printf("Proc %d Finishing Stage 0...\n\r", proc_id);
+    printf("[ Thread %d ] Stage 0: Processor Sorting...\n\r", thread_id);
+
+    bubbleSort(array0, IPP, IPP * thread_id);
+
+    printf("[ Thread %d ] Finishing Stage 0\n\r", thread_id);
 
     for (i = 0; i < __builtin_ctz(NPROCS); i++)
@@ -157,7 +133,11 @@
         barrier_wait(&barrier[i]);
 
-        printf("Proc %d Stage %d: Starting...\n\r", proc_id, i+1);
-
-        if((proc_id % (2 << i)) != 0) exit();
+        if((thread_id % (2 << i)) != 0)
+        {
+            printf("[ Thread %d ] Quits\n\r", thread_id);
+            exit();
+        }
+
+        printf("[ Thread %d ] Stage %d: Starting...\n\r", thread_id, i+1);
 
         if((i % 2) == 0)
@@ -174,10 +154,10 @@
         merge(src_array, dst_array
                 , IPP << i
-                , IPP * proc_id
-                , IPP * (proc_id + (1 << i))
-                , IPP * proc_id
+                , IPP * thread_id
+                , IPP * (thread_id + (1 << i))
+                , IPP * thread_id
                 );
 
-        printf("Proc %d Finishing Stage %d...\n\r", proc_id, i + 1);
+        printf("[ Thread %d ] Finishing Stage %d\n\r", thread_id, i + 1);
     }
 
@@ -188,5 +168,5 @@
     // Verify the resulting array
 
-    if(proc_id == 0)
+    if(thread_id == 0)
     {
         success = 1;
@@ -205,9 +185,9 @@
         if (success)
         {
-            printf("Success!!\n\r");
+            printf("[ Thread 0 ] Success!!\n\r");
         }
         else
         {
-            printf("Failure!! Incorrect element: %d\n\r", failure_index);
+            printf("[ Thread 0 ] Failure!! Incorrect element: %d\n\r", failure_index);
 
 
