tst-eintr1.c 2.1 KB

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