1 /* BZ #17977 _res_hconf_reorder_addrs test.
3 Copyright (C) 2015-2016 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
27 #include <netinet/in.h>
28 #include <sys/socket.h>
30 static struct timespec ts
;
32 /* The first thread that gets a lock in _res_hconf_reorder_addrs()
33 should hold the lock long enough to make two other threads blocked.
34 This is achieved by slowing down realloc(3) that is called several times
35 by _res_hconf_reorder_addrs(). */
38 realloc (void *ptr
, size_t len
)
40 static void *(*fun
) (void *, size_t);
43 fun
= dlsym (RTLD_NEXT
, "realloc");
46 nanosleep (&ts
, NULL
);
48 return (*fun
) (ptr
, len
);
56 struct hostent
*result
;
60 addr
.s_addr
= htonl (INADDR_LOOPBACK
);
61 (void) gethostbyaddr_r ((void *) &addr
, sizeof (addr
), AF_INET
,
62 &ent
, buf
, sizeof (buf
), &result
, &err
);
74 /* turn on realloc slowdown */
75 ts
.tv_nsec
= 100000000;
77 for (i
= 0; i
< N
; ++i
)
79 int rc
= pthread_create (&thr
[i
], NULL
, resolve
, NULL
);
83 printf ("pthread_create: %s\n", strerror(rc
));
88 for (i
= 0; i
< N
; ++i
)
91 int rc
= pthread_join (thr
[i
], &retval
);
95 printf ("pthread_join: %s\n", strerror(rc
));
100 printf ("thread %u exit status %p\n", i
, retval
);
105 /* turn off realloc slowdown, no longer needed */
111 #define TEST_FUNCTION do_test ()
112 #include "../test-skeleton.c"