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)
54
54
55
55
int main ()
56
56
{
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
+
57
61
Thread *thread_list[NUM_THREADS];
58
62
int test_time = 15 ;
59
63
GREENTEA_SETUP (20 , " default_auto" );
60
64
61
65
// Allocate threads for the test
62
66
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 );
64
68
if (NULL == thread_list[i]) {
65
69
allocation_failure = true ;
70
+ } else {
71
+ thread_list[i]->start (task_using_malloc);
66
72
}
67
- thread_list[i]->start (task_using_malloc);
68
73
}
69
74
70
75
// Give the test time to run
You can’t perform that action at this time.
0 commit comments