1 #include "test.h"
2
3 enum {
4 NUMTHREADS = 100
5 };
6
7 static int washere = 0;
8
func(void * arg)9 void * func(void * arg)
10 {
11 washere = 1;
12 return arg;
13 }
14
15 int
main()16 main()
17 {
18 pthread_t t, last_t;
19 void *tp, *last_tp;
20 pthread_attr_t attr;
21 void * result = NULL;
22 int i;
23
24 assert(pthread_attr_init(&attr) == 0);;
25 assert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == 0);
26
27 washere = 0;
28 assert(pthread_create(&t, &attr, func, NULL) == 0);
29 assert(pthread_join(t, &result) == 0);;
30 assert(result == NULL);
31 assert(washere == 1);
32 last_t = t;
33 last_tp = __pth_gpointer_locked (t);
34
35 for (i = 1; i < NUMTHREADS; i++)
36 {
37 washere = 0;
38 assert(pthread_create(&t, &attr, func, (void *) (intptr_t) i) == 0);
39 pthread_join(t, &result);
40 assert((intptr_t) result == (intptr_t) i);
41 assert(washere == 1);
42 /* thread IDs should be unique */
43 assert(!pthread_equal(t, last_t));
44 /* thread struct pointers should be the same */
45 tp = __pth_gpointer_locked(t);
46 assert(tp == last_tp);
47 last_t = t;
48 last_tp = tp;
49 }
50
51 return 0;
52 }
53