[gdb/symtab] Fix gdb.base/fission-macro.exp with unix/-m32
[binutils-gdb.git] / gdb / testsuite / gdb.threads / thread_check.c
blob195841083704c2b3e6e760324f208288c1d08464
1 /* Copyright (C) 2004-2024 Free Software Foundation, Inc.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 This file was written by Steve Munroe (sjmunroe@us.ibm.com). */
18 /* Test break points and single step on thread functions. */
20 #include <string.h>
21 #include <unistd.h>
22 #include <pthread.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <errno.h>
27 #define N 2
29 static void *
30 tf (void *arg)
32 int n = (int) (long int) arg;
33 char number[160];
34 int unslept = 10;
36 sprintf(number, "tf(%ld): begin", (long)arg);
37 puts (number);
39 while (unslept > 0)
40 unslept = sleep(unslept);
42 sprintf(number, "tf(%ld): end", (long)arg);
43 puts (number);
44 return NULL;
47 int main (int argc, char *argv[])
49 int n;
50 int unslept = 2;
51 pthread_t th[N];
53 for (n = 0; n < N; ++n)
54 if (pthread_create (&th[n], NULL, tf, (void *) (long int) n) != 0)
56 while (unslept > 0)
57 unslept = sleep(2);
58 puts ("create failed");
59 exit (1);
62 puts("after create");
64 for (n = 0; n < N; ++n)
65 if (pthread_join (th[n], NULL) != 0)
67 puts ("join failed");
68 exit (1);
71 puts("after join");
72 return 0;