Commit | Line | Data |
---|---|---|
1595475b SM |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
3 | Copyright 2022 Free Software Foundation, Inc. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
17 | ||
18 | #include <pthread.h> | |
19 | #include <unistd.h> | |
20 | #include <sys/types.h> | |
21 | #include <sys/wait.h> | |
22 | #include <errno.h> | |
23 | #include <assert.h> | |
24 | #include <limits.h> | |
25 | ||
26 | /* Number of threads doing forks. */ | |
27 | #define N_FORKERS 4 | |
28 | ||
29 | static void * | |
30 | forker (void *arg) | |
31 | { | |
32 | for (;;) | |
33 | { | |
34 | pid_t pid = FORK_FUNC (); | |
35 | ||
36 | if (pid == 0) | |
37 | _exit(11); | |
38 | ||
39 | assert (pid > 0); | |
40 | ||
41 | /* Wait for children to exit. */ | |
42 | int ret; | |
43 | int stat; | |
44 | do { | |
45 | ret = waitpid (pid, &stat, 0); | |
46 | } while (ret == EINTR); | |
47 | ||
48 | assert (ret == pid); | |
49 | assert (WIFEXITED (stat)); | |
50 | assert (WEXITSTATUS (stat) == 11); | |
51 | ||
52 | usleep (40 * 1000); | |
53 | } | |
54 | ||
55 | return NULL; | |
56 | } | |
57 | ||
58 | static void | |
59 | sleep_a_bit (void) | |
60 | { | |
61 | usleep (1000 * 50); | |
62 | } | |
63 | ||
64 | int | |
65 | main (void) | |
66 | { | |
67 | alarm (60); | |
68 | ||
69 | pthread_t thread[N_FORKERS]; | |
70 | for (int i = 0; i < N_FORKERS; ++i) | |
71 | { | |
72 | int ret = pthread_create (&thread[i], NULL, forker, NULL); | |
73 | assert (ret == 0); | |
74 | } | |
75 | ||
76 | for (int i = 0; i < INT_MAX; ++i) /* for loop */ | |
77 | { | |
78 | sleep_a_bit (); /* break here */ | |
79 | sleep_a_bit (); /* other line */ | |
80 | } | |
81 | ||
82 | for (int i = 0; i < N_FORKERS; ++i) | |
83 | pthread_join (thread[i], NULL); | |
84 | ||
85 | return 0; | |
86 | } |