summaryrefslogtreecommitdiff
path: root/test/pthread/ex1.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-06-30 23:40:40 +0000
committerMike Frysinger <vapier@gentoo.org>2005-06-30 23:40:40 +0000
commit45cba8b94282e00a7ea32e7976d11e3161cb0d1c (patch)
tree588c01e390f6010337e0c6068adba543e34efdda /test/pthread/ex1.c
parent3606882671f95678aecfe9cf6f1b6dad7fb3895f (diff)
exit with an error if thread functions failed so make can detect the problem
Diffstat (limited to 'test/pthread/ex1.c')
-rw-r--r--test/pthread/ex1.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/test/pthread/ex1.c b/test/pthread/ex1.c
index 09e6e3fbd..a1b24c31a 100644
--- a/test/pthread/ex1.c
+++ b/test/pthread/ex1.c
@@ -7,33 +7,29 @@
#include <unistd.h>
#include "pthread.h"
-void * process(void * arg)
+void *process(void * arg)
{
- int i;
- fprintf(stderr, "Starting process %s\n", (char *) arg);
- for (i = 0; i < 10000; i++) {
- write(1, (char *) arg, 1);
- }
- return NULL;
+ int i;
+ printf("Starting process %s\n", (char *)arg);
+ for (i = 0; i < 10000; i++)
+ write(1, (char *) arg, 1);
+ return NULL;
}
+#define sucfail(r) (r != 0 ? "failed" : "succeeded")
int main(void)
{
- int retcode;
- pthread_t th_a, th_b;
- void * retval;
+ int pret, ret = 0;
+ pthread_t th_a, th_b;
+ void *retval;
- retcode = pthread_create(&th_a, NULL, process, (void *) "a");
- if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
- else fprintf(stderr, "create a succeeded %d\n", retcode);
- retcode = pthread_create(&th_b, NULL, process, (void *) "b");
- if (retcode != 0) fprintf(stderr, "create b failed %d\n", retcode);
- else fprintf(stderr, "create b succeeded %d\n", retcode);
- retcode = pthread_join(th_a, &retval);
- if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
- else fprintf(stderr, "join a succeeded %d\n", retcode);
- retcode = pthread_join(th_b, &retval);
- if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
- else fprintf(stderr, "join b succeeded %d\n", retcode);
- return 0;
+ ret += (pret = pthread_create(&th_a, NULL, process, (void *)"a"));
+ printf("create a %s %d\n", sucfail(pret), pret);
+ ret += (pret = pthread_create(&th_b, NULL, process, (void *)"b"));
+ printf("create b %s %d\n", sucfail(pret), pret);
+ ret += (pret = pthread_join(th_a, &retval));
+ printf("join a %s %d\n", sucfail(pret), pret);
+ ret += (pret = pthread_join(th_b, &retval));
+ printf("join b %s %d\n", sucfail(pret), pret);
+ return ret;
}