tst-exit1.c 1.9 KB

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