tst-cleanup3.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <pthread.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. static int global;
  20. static void
  21. ch (void *arg)
  22. {
  23. int val = (long int) arg;
  24. printf ("ch (%d)\n", val);
  25. global *= val;
  26. global += val;
  27. }
  28. static void *
  29. tf (void *a)
  30. {
  31. pthread_cleanup_push (ch, (void *) 1l);
  32. pthread_cleanup_push (ch, (void *) 2l);
  33. pthread_cleanup_push (ch, (void *) 3l);
  34. pthread_exit ((void *) 1l);
  35. pthread_cleanup_pop (1);
  36. pthread_cleanup_pop (1);
  37. pthread_cleanup_pop (1);
  38. return NULL;
  39. }
  40. int
  41. do_test (void)
  42. {
  43. pthread_t th;
  44. if (pthread_create (&th, NULL, tf, NULL) != 0)
  45. {
  46. write (2, "create failed\n", 14);
  47. _exit (1);
  48. }
  49. void *r;
  50. int e;
  51. if ((e = pthread_join (th, &r)) != 0)
  52. {
  53. printf ("join failed: %d\n", e);
  54. _exit (1);
  55. }
  56. if (r != (void *) 1l)
  57. {
  58. puts ("thread not canceled");
  59. exit (1);
  60. }
  61. if (global != 9)
  62. {
  63. printf ("global = %d, expected 9\n", global);
  64. exit (1);
  65. }
  66. return 0;
  67. }
  68. #define TEST_FUNCTION do_test ()
  69. #include "../test-skeleton.c"