tst-rwlock5.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <signal.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
  21. static pthread_rwlock_t r;
  22. static void *
  23. tf (void *arg)
  24. {
  25. if (pthread_rwlock_wrlock (&r) == 0)
  26. {
  27. puts ("child: rwlock_wrlock succeeded");
  28. exit (1);
  29. }
  30. puts ("child: rwlock_wrlock returned");
  31. exit (1);
  32. }
  33. static int
  34. do_test (void)
  35. {
  36. pthread_t th;
  37. if (pthread_rwlock_init (&r, NULL) != 0)
  38. {
  39. puts ("rwlock_init failed");
  40. return 1;
  41. }
  42. if (pthread_rwlock_wrlock (&r) != 0)
  43. {
  44. puts ("rwlock_wrlock failed");
  45. return 1;
  46. }
  47. if (pthread_mutex_lock (&m) != 0)
  48. {
  49. puts ("mutex_lock failed");
  50. return 1;
  51. }
  52. /* Set an alarm for 1 second. The wrapper will expect this. */
  53. alarm (1);
  54. if (pthread_create (&th, NULL, tf, NULL) != 0)
  55. {
  56. puts ("create failed");
  57. return 1;
  58. }
  59. /* This call should never return. */
  60. pthread_mutex_lock (&m);
  61. puts ("2nd mutex_lock returned");
  62. return 1;
  63. }
  64. #define EXPECTED_SIGNAL SIGALRM
  65. #define TEST_FUNCTION do_test ()
  66. #include "../test-skeleton.c"