1 /* Copyright (C) 2006 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
30 pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
31 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
42 if (pthread_mutex_lock (&mutex) != 0)
44 puts ("Could not lock mutex in thread");
48 write (fd, &pid, sizeof (int));
50 if (pthread_mutex_unlock (&mutex2) != 0)
52 puts ("Could not unlock mutex2 in thread");
59 if (pthread_cond_timedwait (&cond, &mutex, &ts) != 0)
61 puts ("pthread_cond_wait failed in thread");
65 if (pthread_cond_wait (&cond, &mutex) != 0)
67 puts ("pthread_cond_wait failed in thread");
72 if (pthread_mutex_unlock (&mutex) != 0)
74 puts ("Could not unlock mutex in thread");
95 printf ("couldn't create pipe: %m\n");
102 printf ("fork failed: %m\n");
111 signal (SIGSEGV, sig_segv);
112 pthread_mutex_lock (&mutex2);
113 pthread_create (&thr, NULL, tf, (void *) (long) (fds[1]));
114 /* Wait for the thread to go into cond_wait. */
115 pthread_mutex_lock (&mutex2);
116 pthread_mutex_lock (&mutex);
117 write (fds[1], "", 1);
118 pthread_join (thr, &ret);
125 if (TEMP_FAILURE_RETRY (read (fds[0], &child_pid, sizeof (int)))
128 puts ("could not read pid from child");
133 if (TEMP_FAILURE_RETRY (read (fds[0], &dummy, 1)) != 1)
135 puts ("could not read sync byte from child");
141 /* The sync byte may come immediately after the mutex is released;
142 wait a little bit more to make sure the thread has suspended, to
143 test the right bug. */
146 ts.tv_nsec = 200000000;
147 nanosleep (&ts, NULL);
149 kill (child_pid, SIGSEGV);
153 termpid = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
156 printf ("waitpid failed: %m\n");
159 else if (termpid != pid)
161 printf ("waitpid returned %ld != %ld\n",
162 (long int) termpid, (long int) pid);
165 else if (!WIFEXITED (status) || WEXITSTATUS (status) != 2)
167 puts ("child hasn't exited with exit status 2");
174 #define TEST_FUNCTION do_test ()
175 #include "../test-skeleton.c"