8317919: pthread_attr_init handle return value and destroy pthread_attr_t object

Reviewed-by: mdoerr, lucy
This commit is contained in:
Matthias Baesken 2023-10-13 07:01:50 +00:00
parent ff0b397e13
commit ec310fe809
4 changed files with 16 additions and 4 deletions

View File

@ -769,7 +769,8 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
// Init thread attributes.
pthread_attr_t attr;
pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
guarantee(rslt == 0, "pthread_attr_init has to return 0");
guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
// Make sure we run in 1:1 kernel-user-thread mode.
@ -803,6 +804,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
stack_size / K);
thread->set_osthread(nullptr);
delete osthread;
pthread_attr_destroy(&attr);
return false;
}

View File

@ -911,7 +911,12 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
// init thread attributes
pthread_attr_t attr;
pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
if (rslt != 0) {
thread->set_osthread(nullptr);
delete osthread;
return false;
}
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// Calculate stack size if it's not specified by caller.
@ -960,6 +965,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
stack_size / K);
thread->set_osthread(nullptr);
delete osthread;
pthread_attr_destroy(&attr);
return false;
}

View File

@ -273,8 +273,10 @@ SplashCreateThread(Splash * splash) {
pthread_attr_t attr;
int rc;
pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
if (rslt != 0) return;
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
pthread_attr_destroy(&attr);
}
void

View File

@ -773,8 +773,10 @@ SplashCreateThread(Splash * splash) {
pthread_attr_t attr;
int rc;
pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
if (rslt != 0) return;
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
pthread_attr_destroy(&attr);
}
void