* elf/Versions [GLIBC_PRIVATE]: Export __pointer_chk_guard if defined.
[glibc.git] / nptl / tst-cond9.c
blob2a8477dd8bd757c95bc2e13dd0e5f73e7b8afc29
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include <sys/time.h>
28 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
29 static pthread_mutex_t mut = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
32 static void *
33 tf (void *arg)
35 int err = pthread_cond_wait (&cond, &mut);
36 if (err == 0)
38 puts ("cond_wait did not fail");
39 exit (1);
42 if (err != EPERM)
44 printf ("cond_wait didn't return EPERM but %d\n", err);
45 exit (1);
49 /* Current time. */
50 struct timeval tv;
51 (void) gettimeofday (&tv, NULL);
52 /* +1000 seconds in correct format. */
53 struct timespec ts;
54 TIMEVAL_TO_TIMESPEC (&tv, &ts);
55 ts.tv_sec += 1000;
57 err = pthread_cond_timedwait (&cond, &mut, &ts);
58 if (err == 0)
60 puts ("cond_timedwait did not fail");
61 exit (1);
64 if (err != EPERM)
66 printf ("cond_timedwait didn't return EPERM but %d\n", err);
67 exit (1);
70 return (void *) 1l;
74 static int
75 do_test (void)
77 pthread_t th;
78 int err;
80 printf ("&cond = %p\n&mut = %p\n", &cond, &mut);
82 err = pthread_cond_wait (&cond, &mut);
83 if (err == 0)
85 puts ("cond_wait did not fail");
86 exit (1);
89 if (err != EPERM)
91 printf ("cond_wait didn't return EPERM but %d\n", err);
92 exit (1);
96 /* Current time. */
97 struct timeval tv;
98 (void) gettimeofday (&tv, NULL);
99 /* +1000 seconds in correct format. */
100 struct timespec ts;
101 TIMEVAL_TO_TIMESPEC (&tv, &ts);
102 ts.tv_sec += 1000;
104 err = pthread_cond_timedwait (&cond, &mut, &ts);
105 if (err == 0)
107 puts ("cond_timedwait did not fail");
108 exit (1);
111 if (err != EPERM)
113 printf ("cond_timedwait didn't return EPERM but %d\n", err);
114 exit (1);
117 if (pthread_mutex_lock (&mut) != 0)
119 puts ("parent: mutex_lock failed");
120 exit (1);
123 puts ("creating thread");
125 if (pthread_create (&th, NULL, tf, NULL) != 0)
127 puts ("create failed");
128 exit (1);
131 void *r;
132 if (pthread_join (th, &r) != 0)
134 puts ("join failed");
135 exit (1);
137 if (r != (void *) 1l)
139 puts ("thread has wrong return value");
140 exit (1);
143 puts ("done");
145 return 0;
149 #define TEST_FUNCTION do_test ()
150 #include "../test-skeleton.c"