tst-eintr1.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #define _GNU_SOURCE 1
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include <signal.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "eintr.c"
  23. static void *
  24. tf2 (void *arg)
  25. {
  26. return arg;
  27. }
  28. static void *
  29. tf1 (void *arg)
  30. {
  31. while (1)
  32. {
  33. pthread_t th;
  34. int e = pthread_create (&th, NULL, tf2, NULL);
  35. if (e != 0)
  36. {
  37. if (e == EINTR)
  38. {
  39. puts ("pthread_create returned EINTR");
  40. exit (1);
  41. }
  42. char buf[100];
  43. printf ("tf1: pthread_create failed: %s\n",
  44. strerror_r (e, buf, sizeof (buf)));
  45. exit (1);
  46. }
  47. e = pthread_join (th, NULL);
  48. if (e != 0)
  49. {
  50. if (e == EINTR)
  51. {
  52. puts ("pthread_join returned EINTR");
  53. exit (1);
  54. }
  55. char buf[100];
  56. printf ("tf1: pthread_join failed: %s\n",
  57. strerror_r (e, buf, sizeof (buf)));
  58. exit (1);
  59. }
  60. }
  61. }
  62. static int
  63. do_test (void)
  64. {
  65. setup_eintr (SIGUSR1, NULL);
  66. int i;
  67. for (i = 0; i < 10; ++i)
  68. {
  69. pthread_t th;
  70. int e = pthread_create (&th, NULL, tf1, NULL);
  71. if (e != 0)
  72. {
  73. char buf[100];
  74. printf ("main: pthread_create failed: %s\n",
  75. strerror_r (e, buf, sizeof (buf)));
  76. exit (1);
  77. }
  78. }
  79. (void) tf1 (NULL);
  80. /* NOTREACHED */
  81. return 0;
  82. }
  83. #define EXPECTED_SIGNAL SIGALRM
  84. #define TIMEOUT 3
  85. #define TEST_FUNCTION do_test ()
  86. #include "../test-skeleton.c"