This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hi TI,
Following is my sample code to create detached pthread, why it keep occupying heap memory when it finished its task?
Please help. Thanks.
pthread_t create_thread(const int priority, callback cb, void *args)
{
pthread_t pid = NULL;
pthread_attr_t attrs;
struct sched_param schedule;
do {
pthread_attr_init(&attrs);
schedule.sched_priority = priority;
pthread_attr_setschedparam(&attrs, &schedule);
if (pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) != 0) {
error("fail to setdetachstate\n");
break;
}
if (pthread_attr_setstacksize(&attrs, 4096) != 0) {
error("fail to setstacksize\n");
break;
}
if (pthread_create(&pid, &attrs, cb, args) != 0) {
error("fail to create thread\n");
break;
}
} while (false);
pthread_attr_destroy(&attrs);
return pid;
}
Hi Eric,
How is the thread terminating? Is it being deleted or just falling out of the thread entry function? What is the underlying OS...FreeRTOS or TI-RTOS?
Todd
Hi ToddMullanix,
I am using TI-RTOS. And following code is how the thread terminate. Thanks.
void *my_thread_task(void *args) { info("enter thread\n"); pthread_exit(NULL); return NULL; }
Hi ToddMullanix,
Yes, I can see _pthread_cleanupFxn running when I tested my code.
And at the same time, I checked the heap when pthread finished its task.
Check again.
Heap continue occupying by pthread. How to fix this issue? Any wrong with my sample code? Thanks.
Hi Eric,
Can you put a breakpoint in _pthread_cleanupFxn and confirm it is being hit? If Idle never runs, the memory will not be cleaned up.
Another thing you can try is to use HeapTrack to see who (and when) is allocating memory. Take a look at https://training.ti.com/debugging-common-application-issues-ti-rtos. It covers how to use HeapTrack in the last section. There is a pdf on the page in case you don't want to watch the video.
Note: for the SimpleLink SDK, the debug kernel project enables HeapTrack. Take a look at the SimpleLink SDK's User Guide to see how to use the debug kernel project (instead of the default release kernel project).
Todd
Eric,
Take a look at ROV->Task Detailed. Is there a task that never gives up the processor and thus never allows Idle to run?
Todd
Hi ToddMullanix,
Thanks. I figure out the problem. Because we use UART_readPolling which it keep thread running on the background.
Now, we use UART_read/write instead of Polling, anything looks good. Thanks.