]> granicus.if.org Git - gc/commitdiff
Check pthread_create/join result in initsecondarythread test.
authorIvan Maidanski <ivmai@mail.ru>
Wed, 31 Aug 2011 10:19:34 +0000 (14:19 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 31 Aug 2011 10:19:34 +0000 (14:19 +0400)
* 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

index 2af97243f36e0fde3879ec7e1b68db815858b896..0f97ad318596302481ad34f0699e01646f4facfe 100644 (file)
 #endif
 
 #define GC_NO_THREAD_REDIRECTS 1
+                /* Do not redirect thread creation and join calls.      */
 
 #include "gc.h"
 
 #include <pthread.h>
+
 #include <stdlib.h>
+#include <stdio.h>
 
 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;
 }