tst-barrier1.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <errno.h>
  16. #include <pthread.h>
  17. #include <stdio.h>
  18. static int
  19. do_test (void)
  20. {
  21. pthread_barrier_t b;
  22. int e;
  23. int cnt;
  24. e = pthread_barrier_init (&b, NULL, 0);
  25. if (e == 0)
  26. {
  27. puts ("barrier_init with count 0 succeeded");
  28. return 1;
  29. }
  30. if (e != EINVAL)
  31. {
  32. puts ("barrier_init with count 0 didn't return EINVAL");
  33. return 1;
  34. }
  35. if (pthread_barrier_init (&b, NULL, 1) != 0)
  36. {
  37. puts ("real barrier_init failed");
  38. return 1;
  39. }
  40. for (cnt = 0; cnt < 10; ++cnt)
  41. {
  42. e = pthread_barrier_wait (&b);
  43. if (e != PTHREAD_BARRIER_SERIAL_THREAD)
  44. {
  45. puts ("barrier_wait didn't return PTHREAD_BARRIER_SERIAL_THREAD");
  46. return 1;
  47. }
  48. }
  49. if (pthread_barrier_destroy (&b) != 0)
  50. {
  51. puts ("barrier_destroy failed");
  52. return 1;
  53. }
  54. return 0;
  55. }
  56. #define TEST_FUNCTION do_test ()
  57. #include "../test-skeleton.c"