tst-eintr1.c 2.1 KB

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