• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <assert.h>
3 #include "thread-test.h"
4 
5 extern int add1(int, int);
6 extern int add2(int, int, int);
7 
8 static sem_t done;
9 
10 
start_routine_1(void * arg)11 static void *start_routine_1(void *arg)
12 {
13     int x, status;
14     x = add1(40, 2);
15     assert(x == 42);
16 
17     status = sem_post(&done);
18     assert(status == 0);
19 
20     return arg;
21 }
22 
start_routine_2(void * arg)23 static void *start_routine_2(void *arg)
24 {
25     int x, status;
26 #ifdef T2TEST_AGAIN_ADD1
27     add1(-1, -1);
28 #endif
29     x = add2(1000, 200, 30);
30     assert(x == 1230);
31 
32     status = sem_post(&done);
33     assert(status == 0);
34 
35     return arg;
36 }
37 
main(void)38 int main(void)
39 {
40     pthread_t th;
41     int i, status = sem_init(&done, 0, 0);
42     assert(status == 0);
43 
44     printf("starting\n");
45     fflush(stdout);
46     status = pthread_create(&th, NULL, start_routine_1, NULL);
47     assert(status == 0);
48     status = pthread_create(&th, NULL, start_routine_2, NULL);
49     assert(status == 0);
50 
51     for (i = 0; i < 2; i++) {
52         status = sem_wait(&done);
53         assert(status == 0);
54     }
55     printf("done\n");
56     return 0;
57 }
58