Skip to content

Commit

Permalink
libphoenix: fix locking in pthread_create
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdebek committed Oct 18, 2023
1 parent 367c8ee commit f6020eb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,25 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
ctx->cancelstate = PTHREAD_CANCEL_ENABLE;
*thread = (pthread_t)ctx;

mutexLock(pthread_common.pthread_list_lock);

int err = beginthreadex(start_point, attrs->priority, stack,
attrs->stacksize, (void *)ctx, &ctx->id);

if (err != 0) {
munmap(stack, attrs->stacksize);
pthread_ctx_put(ctx);
_pthread_ctx_put(ctx);
thread = NULL;
}
else if (ctx->detached == PTHREAD_CREATE_JOINABLE) {
mutexLock(pthread_common.pthread_list_lock);
if (pthread_common.pthread_list != NULL && pthread_common.pthread_list->id == 0)
if (pthread_common.pthread_list != NULL && pthread_common.pthread_list->id == 0) {
pthread_common.pthread_list = NULL;

}
LIST_ADD(&pthread_common.pthread_list, ctx);
mutexUnlock(pthread_common.pthread_list_lock);
}

mutexUnlock(pthread_common.pthread_list_lock);

return -err;
}

Expand Down

0 comments on commit f6020eb

Please sign in to comment.