tst-tsd5.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright (C) 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
  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. #include <stdlib.h>
  19. static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
  20. static void
  21. cl (void *p)
  22. {
  23. pthread_mutex_unlock (&m);
  24. }
  25. static void *
  26. tf (void *arg)
  27. {
  28. if (pthread_mutex_lock (&m) != 0)
  29. {
  30. puts ("2nd mutex_lock failed");
  31. exit (1);
  32. }
  33. exit (0);
  34. }
  35. static int
  36. do_test (void)
  37. {
  38. pthread_key_t k;
  39. if (pthread_key_create (&k, cl) != 0)
  40. {
  41. puts ("key_create failed");
  42. return 1;
  43. }
  44. if (pthread_setspecific (k, (void *) 1) != 0)
  45. {
  46. puts ("setspecific failed");
  47. return 1;
  48. }
  49. if (pthread_mutex_lock (&m) != 0)
  50. {
  51. puts ("1st mutex_lock failed");
  52. return 1;
  53. }
  54. pthread_t th;
  55. if (pthread_create (&th, NULL, tf, NULL) != 0)
  56. {
  57. puts ("create failed");
  58. return 1;
  59. }
  60. pthread_exit (NULL);
  61. }
  62. #define TEST_FUNCTION do_test ()
  63. #include "../test-skeleton.c"