tst-rwlock3.c 2.5 KB

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