An example of running multiple thread instances of the same function. Memory is being allocated dynamically.

Dependencies:   Threads mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
lemniskata
Date:
Sat Jun 29 21:18:14 2013 +0000
Parent:
0:06fdc09661c2
Child:
2:78d8f8cac107
Commit message:
An example of running multiple thread instances of the same function. Memory is being allocated dynamically.

Changed in this revision

Threads.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Threads.lib	Sat Jun 29 21:14:20 2013 +0000
+++ b/Threads.lib	Sat Jun 29 21:18:14 2013 +0000
@@ -1,1 +1,1 @@
-Threads#266b0dc4f8d0
+Threads#ecdd97ea3d3b
--- a/main.cpp	Sat Jun 29 21:14:20 2013 +0000
+++ b/main.cpp	Sat Jun 29 21:18:14 2013 +0000
@@ -20,23 +20,30 @@
 
 int main() {
 
+    //Create an array of pointers to threads
      osThreadDef_t **my_threads=NULL;
+     
+     //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++; 
         if(i<6)
         {
+            //Reallocate memory for the next thread of the function Do()
              if(reAlloc(&my_threads,Do,i)==0)
             {
                 pc.printf("Thread creation faile\n");
                 return -1;
             }
+            //Start the next thread
             osThreadCreate(my_threads[i-1],(void *) i);
             i++;
         }