• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <assert.h>
3 #include "thread-test.h"
4 
5 #define NTHREADS 10
6 
7 
8 extern int add1(int, int);
9 
10 static sem_t done;
11 
12 
start_routine(void * arg)13 static void *start_routine(void *arg)
14 {
15     int x, status;
16     x = add1(40, 2);
17     assert(x == 42);
18 
19     status = sem_post(&done);
20     assert(status == 0);
21 
22     return arg;
23 }
24 
main(void)25 int main(void)
26 {
27     pthread_t th;
28     int i, status = sem_init(&done, 0, 0);
29     assert(status == 0);
30 
31     printf("starting\n");
32     fflush(stdout);
33     for (i = 0; i < NTHREADS; i++) {
34         status = pthread_create(&th, NULL, start_routine, NULL);
35         assert(status == 0);
36     }
37     for (i = 0; i < NTHREADS; i++) {
38         status = sem_wait(&done);
39         assert(status == 0);
40     }
41     printf("done\n");
42     return 0;
43 }
44