tst-tsd5.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <pthread.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
  19. static void
  20. cl (void *p)
  21. {
  22. pthread_mutex_unlock (&m);
  23. }
  24. static void *
  25. tf (void *arg)
  26. {
  27. if (pthread_mutex_lock (&m) != 0)
  28. {
  29. puts ("2nd mutex_lock failed");
  30. exit (1);
  31. }
  32. exit (0);
  33. }
  34. static int
  35. do_test (void)
  36. {
  37. pthread_key_t k;
  38. if (pthread_key_create (&k, cl) != 0)
  39. {
  40. puts ("key_create failed");
  41. return 1;
  42. }
  43. if (pthread_setspecific (k, (void *) 1) != 0)
  44. {
  45. puts ("setspecific failed");
  46. return 1;
  47. }
  48. if (pthread_mutex_lock (&m) != 0)
  49. {
  50. puts ("1st mutex_lock failed");
  51. return 1;
  52. }
  53. pthread_t th;
  54. if (pthread_create (&th, NULL, tf, NULL) != 0)
  55. {
  56. puts ("create failed");
  57. return 1;
  58. }
  59. pthread_exit (NULL);
  60. }
  61. #define TEST_FUNCTION do_test ()
  62. #include "../test-skeleton.c"