Debian Codegraph @

extra_tests/cffi_tests/embedding/thread2-test.c

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