tst-join1.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <stdlib.h>
  18. static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  19. static void *
  20. tf (void *arg)
  21. {
  22. pthread_t mh = (pthread_t) arg;
  23. void *result;
  24. if (pthread_mutex_unlock (&lock) != 0)
  25. {
  26. puts ("unlock failed");
  27. exit (1);
  28. }
  29. if (pthread_join (mh, &result) != 0)
  30. {
  31. puts ("join failed");
  32. exit (1);
  33. }
  34. if (result != (void *) 42l)
  35. {
  36. printf ("result wrong: expected %p, got %p\n", (void *) 42, result);
  37. exit (1);
  38. }
  39. exit (0);
  40. }
  41. static int
  42. do_test (void)
  43. {
  44. pthread_t th;
  45. if (pthread_mutex_lock (&lock) != 0)
  46. {
  47. puts ("1st lock failed");
  48. exit (1);
  49. }
  50. if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
  51. {
  52. puts ("create failed");
  53. exit (1);
  54. }
  55. if (pthread_mutex_lock (&lock) != 0)
  56. {
  57. puts ("2nd lock failed");
  58. exit (1);
  59. }
  60. pthread_exit ((void *) 42);
  61. }
  62. #define TEST_FUNCTION do_test ()
  63. #include "../test-skeleton.c"