From 1de2070a60904e0bcb1e6be66a62257ac2a8dfa6 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 31 Aug 2011 14:19:34 +0400 Subject: [PATCH] Check pthread_create/join result in initsecondarythread test. * tests/initsecondarythread.c (GC_NO_THREAD_REDIRECTS): Add comment. * tests/initsecondarythread.c: Include stdio.h. * tests/initsecondarythread.c (thread): Cast result of malloc to void; return arg parameter instead of NULL (to suppress compiler warnings). * tests/initsecondarythread.c (main): Define "code" local variable; store result of pthread_create and pthread_join to "code" variable; exit application with an error code (with the corresponding error message) if pthread_create or pthread_join fails. --- tests/initsecondarythread.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/initsecondarythread.c b/tests/initsecondarythread.c index 2af97243..0f97ad31 100644 --- a/tests/initsecondarythread.c +++ b/tests/initsecondarythread.c @@ -20,24 +20,28 @@ #endif #define GC_NO_THREAD_REDIRECTS 1 + /* Do not redirect thread creation and join calls. */ #include "gc.h" #include + #include +#include static void *thread(void *arg) { GC_INIT(); - GC_MALLOC(123); - GC_MALLOC(12345); - return NULL; + (void)GC_MALLOC(123); + (void)GC_MALLOC(12345); + return arg; } #include "private/gcconfig.h" int main(void) { + int code; pthread_t t; # if !(defined(BEOS) || defined(MSWIN32) || defined(MSWINCE) \ || defined(CYGWIN32) || defined(GC_OPENBSD_THREADS) \ @@ -49,7 +53,13 @@ int main(void) /* GC_INIT() must be called from main thread only. */ GC_INIT(); # endif - pthread_create (&t, NULL, thread, NULL); - pthread_join (t, NULL); + if ((code = pthread_create (&t, NULL, thread, NULL)) != 0) { + printf("Thread creation failed %d\n", code); + return 1; + } + if ((code = pthread_join (t, NULL)) != 0) { + printf("Thread join failed %d\n", code); + return 1; + } return 0; } -- 2.50.1