summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2011-08-31 12:19:34 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-09-12 12:22:38 +0200
commit650921e4ae058968f3c720d16716bb1bced4d16b (patch)
tree6a73746faf2da52a963f3f3e2611547b6f07e193 /tests
parent7ed3cb966f05416dd583ed76fe203d2b5f0ddc04 (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/initsecondarythread.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/initsecondarythread.c b/tests/initsecondarythread.c
index f89252e..054d672 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 <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;
}