tst-rwlock1.c 2.8 KB

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