ignore invalid DOF provider sections
[binutils-gdb.git] / gdb / testsuite / gdb.threads / next-while-other-thread-longjmps.c
blob4733b8f4b733db2382bfa862fac8b725afbf1183
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/>. */
18 #include <assert.h>
19 #include <pthread.h>
20 #include <unistd.h>
21 #include <setjmp.h>
23 /* Number of threads. */
24 #define NTHREADS 10
26 /* When set, threads exit. */
27 volatile int break_out;
29 pthread_barrier_t barrier;
31 /* Entry point for threads that setjmp/longjmp. */
33 static void *
34 thread_longjmp (void *arg)
36 jmp_buf env;
38 pthread_barrier_wait (&barrier);
40 while (!break_out)
42 if (setjmp (env) == 0)
43 longjmp (env, 1);
45 usleep (1);
47 return NULL;
50 /* Entry point for threads that try/catch. */
52 static void *
53 thread_try_catch (void *arg)
55 volatile unsigned int counter = 0;
57 pthread_barrier_wait (&barrier);
59 while (!break_out)
61 try
63 throw 1;
65 catch (...)
67 counter++;
70 usleep (1);
72 return NULL;
75 int
76 main (void)
78 pthread_t threads[NTHREADS];
79 int i;
80 int ret;
82 /* Don't run forever. */
83 alarm (180);
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
90 try/catch. */
91 if ((i % 2) == 0)
92 ret = pthread_create (&threads[i], NULL, thread_longjmp , NULL);
93 else
94 ret = pthread_create (&threads[i], NULL, thread_try_catch , NULL);
95 assert (ret == 0);
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 */
107 LINE; /* line 1 */
108 LINE; /* line 2 */
109 LINE; /* line 3 */
110 LINE; /* line 4 */
111 LINE; /* line 5 */
112 LINE; /* line 6 */
113 LINE; /* line 7 */
114 LINE; /* line 8 */
115 LINE; /* line 9 */
116 LINE; /* line 10 */
118 break_out = 1;
120 for (i = 0; i < NTHREADS; i++)
122 ret = pthread_join (threads[i], NULL);
123 assert (ret == 0);
126 return 0;