tst-fini1mod.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright (C) 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
  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 <stdio.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. static void *
  20. tf (void *arg)
  21. {
  22. int fds[2];
  23. if (pipe (fds) != 0)
  24. {
  25. puts ("pipe failed");
  26. exit (1);
  27. }
  28. char buf[10];
  29. read (fds[0], buf, sizeof (buf));
  30. puts ("read returned");
  31. exit (1);
  32. }
  33. static pthread_t th;
  34. static void
  35. __attribute ((destructor))
  36. dest (void)
  37. {
  38. if (pthread_cancel (th) != 0)
  39. {
  40. puts ("cancel failed");
  41. _exit (1);
  42. }
  43. void *r;
  44. if (pthread_join (th, &r) != 0)
  45. {
  46. puts ("join failed");
  47. _exit (1);
  48. }
  49. /* Exit successfully. */
  50. _exit (0);
  51. }
  52. void
  53. m (void)
  54. {
  55. if (pthread_create (&th, NULL, tf, NULL) != 0)
  56. {
  57. puts ("create failed");
  58. _exit (1);
  59. }
  60. }