tst-eintr5.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.
  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.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <sys/time.h>
  22. #include "eintr.c"
  23. static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
  24. static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
  25. static void *
  26. tf (void *arg)
  27. {
  28. struct timespec ts;
  29. struct timeval tv;
  30. gettimeofday (&tv, NULL);
  31. TIMEVAL_TO_TIMESPEC (&tv, &ts);
  32. ts.tv_sec += 10000;
  33. /* This call must never return. */
  34. int e = pthread_cond_timedwait (&c, &m, &ts);
  35. char buf[100];
  36. printf ("tf: cond_timedwait returned: %s\n",
  37. strerror_r (e, buf, sizeof (buf)));
  38. exit (1);
  39. }
  40. static int
  41. do_test (void)
  42. {
  43. setup_eintr (SIGUSR1, NULL);
  44. pthread_t th;
  45. char buf[100];
  46. int e = pthread_create (&th, NULL, tf, NULL);
  47. if (e != 0)
  48. {
  49. printf ("main: pthread_create failed: %s\n",
  50. strerror_r (e, buf, sizeof (buf)));
  51. exit (1);
  52. }
  53. /* This call must never return. */
  54. e = pthread_cond_wait (&c, &m);
  55. printf ("main: cond_wait returned: %s\n",
  56. strerror_r (e, buf, sizeof (buf)));
  57. return 0;
  58. }
  59. #define EXPECTED_SIGNAL SIGALRM
  60. #define TIMEOUT 3
  61. #define TEST_FUNCTION do_test ()
  62. #include "../test-skeleton.c"