Skip to content

Commit

Permalink
libphoenix: fix mutexing 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 c1a16ae
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ 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);

Expand All @@ -269,14 +271,14 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
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 c1a16ae

Please sign in to comment.