tst-cancel2.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /* The buffer size must be larger than the pipe size so that the
  24. write blocks. */
  25. char buf[100000];
  26. while (write (fd[1], buf, sizeof (buf)) > 0);
  27. return (void *) 42l;
  28. }
  29. static int
  30. do_test (void)
  31. {
  32. pthread_t th;
  33. void *r;
  34. struct sigaction sa;
  35. sa.sa_handler = SIG_IGN;
  36. sigemptyset (&sa.sa_mask);
  37. sa.sa_flags = 0;
  38. if (sigaction (SIGPIPE, &sa, NULL) != 0)
  39. {
  40. puts ("sigaction failed");
  41. return 1;
  42. }
  43. if (pipe (fd) != 0)
  44. {
  45. puts ("pipe failed");
  46. return 1;
  47. }
  48. if (pthread_create (&th, NULL, tf, NULL) != 0)
  49. {
  50. puts ("create failed");
  51. return 1;
  52. }
  53. if (pthread_cancel (th) != 0)
  54. {
  55. puts ("cancel failed");
  56. return 1;
  57. }
  58. /* This will cause the write in the child to return. */
  59. close (fd[0]);
  60. if (pthread_join (th, &r) != 0)
  61. {
  62. puts ("join failed");
  63. return 1;
  64. }
  65. if (r != PTHREAD_CANCELED)
  66. {
  67. printf ("result is wrong: expected %p, got %p\n", PTHREAD_CANCELED, r);
  68. return 1;
  69. }
  70. return 0;
  71. }
  72. #define TEST_FUNCTION do_test ()
  73. #include "../test-skeleton.c"