create a list of threads in C
- by Hristo
My implementation (in C) isn't working... the first node is always NULL so I can't free the memory. I'm doing:
thread_node_t *thread_list_head = NULL; // done in the beginning of the program
...
// later on in the program
thread_node_t *thread = (thread_node_t*) malloc(sizeof(thread_node_t));
pthread_create(&(thread->thread), NULL, client_thread, &csFD);
thread->next = thread_list_head;
thread_list_head = thread;
So when I try to free this memory, thread_list_head is NULL.
while (thread_list_head != NULL) {
thread_node_t *temp = thread_list_head;
thread_list_head = thread_list_head->next;
free(temp);
temp = NULL;
}
Any advice on how to fix this or just a new way to create this list that would work better?
Thanks,
Hristo