Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Threads mbed-rtos mbed
Diff: main.cpp
- Revision:
- 3:681b2f7e1b41
- Parent:
- 1:458d82e37147
- Child:
- 4:a25f2646a1bc
--- 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);