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.
Dependents: MutliThread Server_Multi_Client HelloWorld C027_SupportTest ... more
Revision 3:d370bed31f45, committed 2013-06-29
- Comitter:
- lemniskata
- Date:
- Sat Jun 29 22:59:46 2013 +0000
- Parent:
- 2:46b56c9086f2
- Commit message:
- Running multiple thread instances of the same function. New thread is started only if there are less than MAX non-inactive threads
Changed in this revision
| Threads.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Threads.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Threads.cpp Sat Jun 29 22:05:28 2013 +0000
+++ b/Threads.cpp Sat Jun 29 22:59:46 2013 +0000
@@ -17,10 +17,13 @@
#include "Threads.h"
/*Initialize memory and set the pointer to the thread*/
-int initThread(ThreadList **addresOfTL,os_pthread pthread,ThreadList** addresOfThread)
+int initThread(ThreadList **addresOfTL,os_pthread pthread,ThreadList** addresOfThread,int max)
{
+
if(*addresOfTL==NULL)
{
+ if(max<=0)
+ return 0;
*addresOfTL=(ThreadList*)malloc(sizeof(ThreadList));
if(*addresOfTL==NULL)
return 0;
@@ -45,6 +48,32 @@
return 1;
}
else
- return initThread(&((*addresOfTL)->nextThread),pthread,addresOfThread);
+ {
+ if((*addresOfTL)->thread->tcb.state == 0)
+ {
+ free((*addresOfTL)->thread->stack_pointer);
+ (*addresOfTL)->thread->stack_pointer=NULL;
+ free((*addresOfTL)->thread);
+ (*addresOfTL)->thread=NULL;
+ (*addresOfTL)->thread=(osThreadDef_t *)malloc(sizeof(osThreadDef_t ));
+
+ if((*addresOfTL)->thread==NULL)
+ return 0;
+
+ (*addresOfTL)->thread->pthread=pthread;
+ (*addresOfTL)->thread->tpriority=osPriorityNormal;
+ (*addresOfTL)->thread->stacksize=DEFAULT_STACK_SIZE;
+
+ (*addresOfTL)->thread->stack_pointer=NULL;
+ (*addresOfTL)->thread->stack_pointer=(unsigned char *)malloc(DEFAULT_STACK_SIZE);
+
+ if((*addresOfTL)->thread->stack_pointer==NULL)
+ return 0;
+ (*addresOfThread)=(*addresOfTL);
+ return 1;
+ }
+ else
+ return initThread(&((*addresOfTL)->nextThread),pthread,addresOfThread,--max);
+ }
}
--- a/Threads.h Sat Jun 29 22:05:28 2013 +0000
+++ b/Threads.h Sat Jun 29 22:59:46 2013 +0000
@@ -27,6 +27,6 @@
struct ThreadList* nextThread;
}ThreadList;
-int initThread(ThreadList **addresOfTL,os_pthread pthread,ThreadList** addresOfThread);
+int initThread(ThreadList **addresOfTL,os_pthread pthread,ThreadList** addresOfThread,int max);
#endif