tst-cancel3.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2002 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 <pthread.h>
  16. #include <signal.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. static int fd[2];
  20. static void *
  21. tf (void *arg)
  22. {
  23. char buf[100];
  24. if (read (fd[0], buf, sizeof (buf)) == sizeof (buf))
  25. {
  26. puts ("read succeeded");
  27. return (void *) 1l;
  28. }
  29. return NULL;
  30. }
  31. static int
  32. do_test (void)
  33. {
  34. pthread_t th;
  35. void *r;
  36. struct sigaction sa;
  37. sa.sa_handler = SIG_IGN;
  38. sigemptyset (&sa.sa_mask);
  39. sa.sa_flags = 0;
  40. if (sigaction (SIGPIPE, &sa, NULL) != 0)
  41. {
  42. puts ("sigaction failed");
  43. return 1;
  44. }
  45. if (pipe (fd) != 0)
  46. {
  47. puts ("pipe failed");
  48. return 1;
  49. }
  50. if (pthread_create (&th, NULL, tf, NULL) != 0)
  51. {
  52. puts ("create failed");
  53. return 1;
  54. }
  55. if (pthread_cancel (th) != 0)
  56. {
  57. puts ("cancel failed");
  58. return 1;
  59. }
  60. /* This will cause the read in the child to return. */
  61. close (fd[0]);
  62. if (pthread_join (th, &r) != 0)
  63. {
  64. puts ("join failed");
  65. return 1;
  66. }
  67. if (r != PTHREAD_CANCELED)
  68. {
  69. puts ("result is wrong");
  70. return 1;
  71. }
  72. return 0;
  73. }
  74. #define TEST_FUNCTION do_test ()
  75. #include "../test-skeleton.c"