Ivan Shindev / Mbed 2 deprecated MutliThread

Dependencies:   Threads mbed-rtos mbed

Revision:
3:681b2f7e1b41
Parent:
1:458d82e37147
Child:
4:a25f2646a1bc
diff -r 78d8f8cac107 -r 681b2f7e1b41 main.cpp
--- a/main.cpp	Sat Jun 29 21:19:53 2013 +0000
+++ b/main.cpp	Sat Jun 29 22:06:29 2013 +0000
@@ -19,32 +19,23 @@
 }
 
 int main() {
-
-    //Create an array of pointers to threads
-     osThreadDef_t **my_threads=NULL;
+    ThreadList* my_threads=NULL; //List of all Initialized threads
+    ThreadList* thread; //pointer to the last created ThreadList element
      
-     //Initialize the first thread of the function Do()
-     if(initThread(&my_threads,Do)==0)
-     {
-        pc.printf("Thread creation faile\n");
-        return -1;
-     }
-     int i=1;
-     
-     //Start the first thread
-     osThreadCreate(my_threads[i-1],(void *) i);
-    while(1) {
-         i++; 
+    int i=0; 
+    while(1) 
+    {
+        //We want 6 instances of the Do() function to run in separate threads 
         if(i<6)
         {
-            //Reallocate memory for the next thread of the function Do()
-             if(reAlloc(&my_threads,Do,i)==0)
+            //Initialize a thread 
+            if(initThread(&my_threads,Do,&thread)==0)
             {
                 pc.printf("Thread creation faile\n");
                 return -1;
             }
-            //Start the next thread
-            osThreadCreate(my_threads[i-1],(void *) i);
+            //Start the thread and store the id
+            thread->id=osThreadCreate(thread->thread,(void *) i);
             i++;
         }
         wait(0.2);