File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
TESTS/mbedmicro-rtos-mbed/malloc Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -54,17 +54,22 @@ void task_using_malloc(void)
5454
5555int main ()
5656{
57+ // static stack for threads to reduce heap usage on devices with small RAM
58+ // and eliminate run out of heap memory problem
59+ MBED_ALIGN (8 ) uint8_t stack[THREAD_STACK_SIZE * NUM_THREADS];
60+
5761 Thread *thread_list[NUM_THREADS];
5862 int test_time = 15 ;
5963 GREENTEA_SETUP (20 , " default_auto" );
6064
6165 // Allocate threads for the test
6266 for (int i = 0 ; i < NUM_THREADS; i++) {
63- thread_list[i] = new Thread (osPriorityNormal, THREAD_STACK_SIZE);
67+ thread_list[i] = new Thread (osPriorityNormal, THREAD_STACK_SIZE, stack + i * THREAD_STACK_SIZE );
6468 if (NULL == thread_list[i]) {
6569 allocation_failure = true ;
70+ } else {
71+ thread_list[i]->start (task_using_malloc);
6672 }
67- thread_list[i]->start (task_using_malloc);
6873 }
6974
7075 // Give the test time to run
You can’t perform that action at this time.
0 commit comments