tst-rwlock3.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /* This test case checks more than standard compliance. An
  16. implementation may provide this service but it is not required to
  17. do so. */
  18. #include <errno.h>
  19. #include <pthread.h>
  20. #include <stdio.h>
  21. static int
  22. do_test (void)
  23. {
  24. pthread_rwlock_t r;
  25. int e;
  26. if (pthread_rwlock_init (&r, NULL) != 0)
  27. {
  28. puts ("rwlock_init failed");
  29. return 1;
  30. }
  31. puts ("rwlock_init succeeded");
  32. if (pthread_rwlock_trywrlock (&r) != 0)
  33. {
  34. puts ("rwlock_trywrlock on unlocked rwlock failed");
  35. return 1;
  36. }
  37. puts ("rwlock_trywrlock on unlocked rwlock succeeded");
  38. e = pthread_rwlock_rdlock (&r);
  39. if (e == 0)
  40. {
  41. puts ("rwlock_rdlock on rwlock with writer succeeded");
  42. return 1;
  43. }
  44. if (e != EDEADLK)
  45. {
  46. puts ("rwlock_rdlock on rwlock with writer failed != EDEADLK");
  47. return 1;
  48. }
  49. puts ("rwlock_rdlock on rwlock with writer failed with EDEADLK");
  50. e = pthread_rwlock_wrlock (&r);
  51. if (e == 0)
  52. {
  53. puts ("rwlock_wrlock on rwlock with writer succeeded");
  54. return 1;
  55. }
  56. if (e != EDEADLK)
  57. {
  58. puts ("rwlock_wrlock on rwlock with writer failed != EDEADLK");
  59. return 1;
  60. }
  61. puts ("rwlock_wrlock on rwlock with writer failed with EDEADLK");
  62. if (pthread_rwlock_unlock (&r) != 0)
  63. {
  64. puts ("rwlock_unlock failed");
  65. return 1;
  66. }
  67. puts ("rwlock_unlock succeeded");
  68. if (pthread_rwlock_destroy (&r) != 0)
  69. {
  70. puts ("rwlock_destroy failed");
  71. return 1;
  72. }
  73. puts ("rwlock_destroy succeeded");
  74. return 0;
  75. }
  76. #define TEST_FUNCTION do_test ()
  77. #include "../test-skeleton.c"