]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-eintr1.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / nptl / tst-eintr1.c
CommitLineData
04277e02 1/* Copyright (C) 2003-2019 Free Software Foundation, Inc.
6735470f
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
6735470f
UD
18
19#include <errno.h>
20#include <pthread.h>
21#include <signal.h>
22#include <stdio.h>
23#include <stdlib.h>
675620f7 24#include <string.h>
6735470f 25
7e625f7e
FW
26static int do_test (void);
27
28#define TEST_FUNCTION do_test ()
29#include "../test-skeleton.c"
30
6735470f
UD
31#include "eintr.c"
32
33
34static void *
35tf2 (void *arg)
36{
37 return arg;
38}
39
40
41static void *
42tf1 (void *arg)
43{
44 while (1)
45 {
46 pthread_t th;
47
48 int e = pthread_create (&th, NULL, tf2, NULL);
49 if (e != 0)
50 {
51 if (e == EINTR)
52 {
53 puts ("pthread_create returned EINTR");
54 exit (1);
55 }
56
675620f7
UD
57 char buf[100];
58 printf ("tf1: pthread_create failed: %s\n",
59 strerror_r (e, buf, sizeof (buf)));
6735470f
UD
60 exit (1);
61 }
62
63 e = pthread_join (th, NULL);
64 if (e != 0)
65 {
66 if (e == EINTR)
67 {
68 puts ("pthread_join returned EINTR");
69 exit (1);
70 }
71
675620f7
UD
72 char buf[100];
73 printf ("tf1: pthread_join failed: %s\n",
74 strerror_r (e, buf, sizeof (buf)));
6735470f
UD
75 exit (1);
76 }
77 }
78}
79
80
81static int
82do_test (void)
83{
4efdd8d3 84 setup_eintr (SIGUSR1, NULL);
6735470f
UD
85
86 int i;
87 for (i = 0; i < 10; ++i)
88 {
89 pthread_t th;
675620f7
UD
90 int e = pthread_create (&th, NULL, tf1, NULL);
91 if (e != 0)
6735470f 92 {
675620f7
UD
93 char buf[100];
94 printf ("main: pthread_create failed: %s\n",
95 strerror_r (e, buf, sizeof (buf)));
6735470f
UD
96 exit (1);
97 }
98 }
99
7e625f7e
FW
100 delayed_exit (3);
101 /* This call must never return. */
6735470f 102 (void) tf1 (NULL);
7e625f7e 103 return 1;
6735470f 104}