Skip to content

Commit

Permalink
threads: don't join thread if pthread_create failed; fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfalkenberg committed Sep 22, 2022
1 parent 19918d9 commit ffc9ca5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/src/common/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,17 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void*
int err = pthread_create(thread, attr_enable ? &attr : NULL, start_routine, arg);
if (err) {
if (EPERM == err) {
// Join failed thread for avoiding memory leak from previous trial
pthread_join(*thread, NULL);

perror("Warning: Failed to create thread with real-time priority. Creating it with normal priority");
fprintf(stderr,
"Warning: Failed to create thread with real-time priority. Creating it with normal priority: %s\n",
strerror(err));
err = pthread_create(thread, NULL, start_routine, arg);
if (err) {
perror("pthread_create");
fprintf(stderr, "Error: Failed to create thread with normal priority: %s\n", strerror(err));
} else {
ret = true;
}
} else {
perror("pthread_create");
fprintf(stderr, "Error: Failed to create thread with real-time priority: %s\n", strerror(err));
}
} else {
ret = true;
Expand Down

0 comments on commit ffc9ca5

Please sign in to comment.