tst-rwlock1.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <pthread.h>
  16. #include <stdio.h>
  17. static int
  18. do_test (void)
  19. {
  20. pthread_rwlock_t r;
  21. if (pthread_rwlock_init (&r, NULL) != 0)
  22. {
  23. puts ("rwlock_init failed");
  24. return 1;
  25. }
  26. puts ("rwlock_init succeeded");
  27. if (pthread_rwlock_rdlock (&r) != 0)
  28. {
  29. puts ("1st rwlock_rdlock failed");
  30. return 1;
  31. }
  32. puts ("1st rwlock_rdlock succeeded");
  33. if (pthread_rwlock_rdlock (&r) != 0)
  34. {
  35. puts ("2nd rwlock_rdlock failed");
  36. return 1;
  37. }
  38. puts ("2nd rwlock_rdlock succeeded");
  39. if (pthread_rwlock_unlock (&r) != 0)
  40. {
  41. puts ("1st rwlock_unlock failed");
  42. return 1;
  43. }
  44. puts ("1st rwlock_unlock succeeded");
  45. if (pthread_rwlock_unlock (&r) != 0)
  46. {
  47. puts ("2nd rwlock_unlock failed");
  48. return 1;
  49. }
  50. puts ("2nd rwlock_unlock succeeded");
  51. if (pthread_rwlock_wrlock (&r) != 0)
  52. {
  53. puts ("1st rwlock_wrlock failed");
  54. return 1;
  55. }
  56. puts ("1st rwlock_wrlock succeeded");
  57. if (pthread_rwlock_unlock (&r) != 0)
  58. {
  59. puts ("3rd rwlock_unlock failed");
  60. return 1;
  61. }
  62. puts ("3rd rwlock_unlock succeeded");
  63. if (pthread_rwlock_wrlock (&r) != 0)
  64. {
  65. puts ("2nd rwlock_wrlock failed");
  66. return 1;
  67. }
  68. puts ("2nd rwlock_wrlock succeeded");
  69. if (pthread_rwlock_unlock (&r) != 0)
  70. {
  71. puts ("4th rwlock_unlock failed");
  72. return 1;
  73. }
  74. puts ("4th rwlock_unlock succeeded");
  75. if (pthread_rwlock_rdlock (&r) != 0)
  76. {
  77. puts ("3rd rwlock_rdlock failed");
  78. return 1;
  79. }
  80. puts ("3rd rwlock_rdlock succeeded");
  81. if (pthread_rwlock_unlock (&r) != 0)
  82. {
  83. puts ("5th rwlock_unlock failed");
  84. return 1;
  85. }
  86. puts ("5th rwlock_unlock succeeded");
  87. if (pthread_rwlock_destroy (&r) != 0)
  88. {
  89. puts ("rwlock_destroy failed");
  90. return 1;
  91. }
  92. puts ("rwlock_destroy succeeded");
  93. return 0;
  94. }
  95. #define TEST_FUNCTION do_test ()
  96. #include "../test-skeleton.c"