Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kernel] thread_join from multiple threads #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,28 @@ status_t thread_join(thread_t *t, int *retcode, lk_time_t timeout)
ASSERT(!list_in_list(&t->queue_node));
#endif

/* save the return code */
if (retcode)
*retcode = t->retcode;

/* remove it from the master thread list */
list_delete(&t->thread_list_node);

/* clear the structure's magic */
t->magic = 0;

/* Check if some other thread already reclaimed the thread resources */
if (t) {
/* save the return code */
if (retcode)
*retcode = t->retcode;

/* remove it from the master thread list */
list_delete(&t->thread_list_node);

/* clear the structure's magic */
t->magic = 0;
}
exit_critical_section();

/* free its stack and the thread structure itself */
if (t->flags & THREAD_FLAG_FREE_STACK && t->stack)
free(t->stack);
if (t) {
if (t->flags & THREAD_FLAG_FREE_STACK && t->stack)
free(t->stack);

if (t->flags & THREAD_FLAG_FREE_STRUCT)
free(t);
if (t->flags & THREAD_FLAG_FREE_STRUCT)
free(t);
}

return NO_ERROR;
}
Expand Down