tst-exit1.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 2002, 2003 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. /* NOTE: this tests functionality beyond POSIX. POSIX does not allow
  16. exit to be called more than once. */
  17. #include <pthread.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. static pthread_barrier_t b;
  21. static void *
  22. tf (void *arg)
  23. {
  24. int r = pthread_barrier_wait (&b);
  25. if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
  26. {
  27. puts ("barrier_wait failed");
  28. exit (1);
  29. }
  30. exit (0);
  31. }
  32. static int
  33. do_test (void)
  34. {
  35. if (pthread_barrier_init (&b, NULL, 2) != 0)
  36. {
  37. puts ("barrier_init failed");
  38. exit (1);
  39. }
  40. pthread_t th;
  41. if (pthread_create (&th, NULL, tf, NULL) != 0)
  42. {
  43. puts ("create failed");
  44. exit (1);
  45. }
  46. int r = pthread_barrier_wait (&b);
  47. if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
  48. {
  49. puts ("barrier_wait failed");
  50. exit (1);
  51. }
  52. /* Do nothing. */
  53. if (pthread_join (th, NULL) == 0)
  54. {
  55. puts ("join succeeded!?");
  56. exit (1);
  57. }
  58. puts ("join returned!?");
  59. exit (1);
  60. }
  61. #define TEST_FUNCTION do_test ()
  62. #include "../test-skeleton.c"