1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2015 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* Number of threads. */
26 /* When set, threads exit. */
27 volatile int break_out
;
29 pthread_barrier_t barrier
;
31 /* Entry point for threads that setjmp/longjmp. */
34 thread_longjmp (void *arg
)
38 pthread_barrier_wait (&barrier
);
42 if (setjmp (env
) == 0)
50 /* Entry point for threads that try/catch. */
53 thread_try_catch (void *arg
)
55 volatile unsigned int counter
= 0;
57 pthread_barrier_wait (&barrier
);
78 pthread_t threads
[NTHREADS
];
82 /* Don't run forever. */
85 pthread_barrier_init (&barrier
, NULL
, NTHREADS
+ 1);
87 for (i
= 0; i
< NTHREADS
; i
++)
89 /* Half of the threads does setjmp/longjmp, the other half does
92 ret
= pthread_create (&threads
[i
], NULL
, thread_longjmp
, NULL
);
94 ret
= pthread_create (&threads
[i
], NULL
, thread_try_catch
, NULL
);
98 /* Wait until all threads are running. */
99 pthread_barrier_wait (&barrier
);
101 #define LINE usleep (1)
103 /* The other thread's setjmp/longjmp/try/catch should not disturb
104 this thread's stepping over these lines. */
106 LINE
; /* set break here */
120 for (i
= 0; i
< NTHREADS
; i
++)
122 ret
= pthread_join (threads
[i
], NULL
);