struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tcc / 116_bound_setjmp2.c
blob151114d9e1a922e0436829daafa34916e0104e07
1 #include <stdio.h>
2 #include <string.h>
3 #include <setjmp.h>
4 #if !defined(_WIN32)
5 #include <pthread.h>
6 #else
7 #include <windows.h>
8 #endif
10 #define SIZE 10
11 #define COUNT 10
13 #define TST int i, a[2], b[2]; \
14 for (i = 0; i < 2; i++) a[i] = 0; \
15 for (i = 0; i < 2; i++) b[i] = 0
17 static int count[SIZE];
19 static void tst1 (jmp_buf loc)
21 TST;
22 longjmp(loc, 1);
25 static void tst2(jmp_buf loc)
27 jmp_buf jmp;
29 setjmp (jmp);
30 TST;
31 tst1(loc);
34 static void *tst (void * index)
36 jmp_buf loc;
37 int i = *(int *) index;
38 static int v[SIZE];
40 for (v[i] = 0; v[i] < COUNT; v[i]++) {
41 if (setjmp (loc) == 0) {
42 TST;
43 tst2(loc);
45 else {
46 count[i]++;
48 i = *(int *) index;
50 return NULL;
53 int
54 main (void)
56 int i;
57 #if !defined(_WIN32)
58 pthread_t id[SIZE];
59 #else
60 HANDLE id[SIZE];
61 #endif
62 int index[SIZE];
64 for (i = 0; i < SIZE; i++) {
65 index[i] = i;
66 #if !defined(_WIN32)
67 pthread_create (&id[i], NULL, tst, (void *) &index[i]);
68 #else
69 id[i] = CreateThread(NULL, 8192, (LPTHREAD_START_ROUTINE) tst, (void *) &index[i], 0, NULL);
70 #endif
72 for (i = 0; i < SIZE; i++) {
73 #if !defined(_WIN32)
74 pthread_join (id[i], NULL);
75 #else
76 WaitForSingleObject(id[i], INFINITE);
77 #endif
79 for (i = 0; i < SIZE; i++) {
80 if (count[i] != COUNT)
81 printf ("error: %d %d\n", i, count[i]);
83 return 0;