tst-join5.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  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 <errno.h>
  17. #include <pthread.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. static void *
  21. tf1 (void *arg)
  22. {
  23. pthread_join ((pthread_t) arg, NULL);
  24. puts ("1st join returned");
  25. return (void *) 1l;
  26. }
  27. static void *
  28. tf2 (void *arg)
  29. {
  30. int a;
  31. a = pthread_join ((pthread_t) arg, NULL);
  32. puts ("2nd join returned");
  33. printf("a = %i\n", a);
  34. return (void *) 1l;
  35. }
  36. static int
  37. do_test (void)
  38. {
  39. pthread_t th;
  40. int err = pthread_join (pthread_self (), NULL);
  41. if (err == 0)
  42. {
  43. puts ("1st circular join succeeded");
  44. exit (1);
  45. }
  46. if (err != EDEADLK)
  47. {
  48. printf ("1st circular join %d, not EDEADLK\n", err);
  49. exit (1);
  50. }
  51. if (pthread_create (&th, NULL, tf1, (void *) pthread_self ()) != 0)
  52. {
  53. puts ("1st create failed");
  54. exit (1);
  55. }
  56. if (pthread_cancel (th) != 0)
  57. {
  58. puts ("cannot cancel 1st thread");
  59. exit (1);
  60. }
  61. void *r;
  62. err = pthread_join (th, &r);
  63. if (err != 0)
  64. {
  65. printf ("cannot join 1st thread: %d\n", err);
  66. exit (1);
  67. }
  68. if (r != PTHREAD_CANCELED)
  69. {
  70. puts ("1st thread not canceled");
  71. exit (1);
  72. }
  73. err = pthread_join (pthread_self (), NULL);
  74. if (err == 0)
  75. {
  76. puts ("2nd circular join succeeded");
  77. exit (1);
  78. }
  79. if (err != EDEADLK)
  80. {
  81. printf ("2nd circular join %d, not EDEADLK\n", err);
  82. exit (1);
  83. }
  84. if (pthread_create (&th, NULL, tf2, (void *) pthread_self ()) != 0)
  85. {
  86. puts ("2nd create failed");
  87. exit (1);
  88. }
  89. if (pthread_cancel (th) != 0)
  90. {
  91. puts ("cannot cancel 2nd thread");
  92. exit (1);
  93. }
  94. if (pthread_join (th, &r) != 0)
  95. {
  96. puts ("cannot join 2nd thread");
  97. exit (1);
  98. }
  99. if (r != PTHREAD_CANCELED)
  100. {
  101. puts ("2nd thread not canceled");
  102. exit (1);
  103. }
  104. err = pthread_join (pthread_self (), NULL);
  105. if (err == 0)
  106. {
  107. puts ("2nd circular join succeeded");
  108. exit (1);
  109. }
  110. if (err != EDEADLK)
  111. {
  112. printf ("2nd circular join %d, not EDEADLK\n", err);
  113. exit (1);
  114. }
  115. exit (0);
  116. }
  117. #define TEST_FUNCTION do_test ()
  118. #include "../test-skeleton.c"