1 /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
27 thread_function (void * arg
)
29 int i
= (intptr_t) arg
;
38 printf ("%ld for %d\n", (long int) getpid (), i
);
39 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 * i
};
40 nanosleep (&ts
, NULL
);
44 printf ("fork: %m\n");
49 pid2
= TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0));
52 printf ("waitpid returned %ld, expected %ld\n",
53 (long int) pid2
, (long int) pid
);
57 printf ("%ld with %d, expected %d\n",
58 (long int) pid
, WEXITSTATUS (status
), i
);
60 return WEXITSTATUS (status
) == i
? NULL
: (void *) 1l;
64 static const int t
[N
] = { 7, 6, 5, 4, 3 };
74 if (pthread_attr_init (&at
) != 0)
76 puts ("attr_init failed");
80 if (pthread_attr_setstacksize (&at
, 1 * 1024 * 1024) != 0)
82 puts ("attr_setstacksize failed");
86 for (i
= 0; i
< N
; ++i
)
87 if (pthread_create (&th
[i
], NULL
, thread_function
,
88 (void *) (intptr_t) t
[i
]) != 0)
90 printf ("creation of thread %d failed\n", i
);
94 if (pthread_attr_destroy (&at
) != 0)
96 puts ("attr_destroy failed");
100 for (i
= 0; i
< N
; ++i
)
103 if (pthread_join (th
[i
], &v
) != 0)
105 printf ("join of thread %d failed\n", i
);
110 printf ("join %d successful, but child failed\n", i
);
114 printf ("join %d successful\n", i
);
120 #include <support/test-driver.c>