1*10465441SEvalZero /* Creates two threads, one printing 10000 "a"s, the other printing
2*10465441SEvalZero 10000 "b"s.
3*10465441SEvalZero Illustrates: thread creation, thread joining. */
4*10465441SEvalZero
5*10465441SEvalZero #include <stddef.h>
6*10465441SEvalZero #include <stdio.h>
7*10465441SEvalZero #include <unistd.h>
8*10465441SEvalZero #include "pthread.h"
9*10465441SEvalZero
process(void * arg)10*10465441SEvalZero static void *process(void * arg)
11*10465441SEvalZero {
12*10465441SEvalZero int i;
13*10465441SEvalZero printf("Starting process %s\n", (char *)arg);
14*10465441SEvalZero for (i = 0; i < 10000; i++)
15*10465441SEvalZero write(1, (char *) arg, 1);
16*10465441SEvalZero return NULL;
17*10465441SEvalZero }
18*10465441SEvalZero
19*10465441SEvalZero #define sucfail(r) (r != 0 ? "failed" : "succeeded")
libc_ex1(void)20*10465441SEvalZero int libc_ex1(void)
21*10465441SEvalZero {
22*10465441SEvalZero int pret, ret = 0;
23*10465441SEvalZero pthread_t th_a, th_b;
24*10465441SEvalZero void *retval;
25*10465441SEvalZero
26*10465441SEvalZero ret += (pret = pthread_create(&th_a, NULL, process, (void *)"a"));
27*10465441SEvalZero printf("create a %s %d\n", sucfail(pret), pret);
28*10465441SEvalZero ret += (pret = pthread_create(&th_b, NULL, process, (void *)"b"));
29*10465441SEvalZero printf("create b %s %d\n", sucfail(pret), pret);
30*10465441SEvalZero ret += (pret = pthread_join(th_a, &retval));
31*10465441SEvalZero printf("join a %s %d\n", sucfail(pret), pret);
32*10465441SEvalZero ret += (pret = pthread_join(th_b, &retval));
33*10465441SEvalZero printf("join b %s %d\n", sucfail(pret), pret);
34*10465441SEvalZero return ret;
35*10465441SEvalZero }
36*10465441SEvalZero #include <finsh.h>
37*10465441SEvalZero FINSH_FUNCTION_EXPORT(libc_ex1, example 1 for libc);
38