tst-tsd4.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <limits.h>
  16. #include <pthread.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. static pthread_key_t key;
  21. static int rounds;
  22. static void
  23. destr (void *arg)
  24. {
  25. ++rounds;
  26. if (pthread_setspecific (key, (void *) 1l) != 0)
  27. {
  28. puts ("destr: setspecific failed");
  29. exit (1);
  30. }
  31. }
  32. static void *
  33. tf (void *arg)
  34. {
  35. if (pthread_setspecific (key, (void *) 1l) != 0)
  36. {
  37. puts ("tf: setspecific failed");
  38. exit (1);
  39. }
  40. return NULL;
  41. }
  42. /* This test check non-standard behavior. The standard does not
  43. require that the implementation has to stop calling TSD destructors
  44. when they are set over and over again. But NPTL does. */
  45. static int
  46. do_test (void)
  47. {
  48. /* Allocate two keys, both with destructors. */
  49. if (pthread_key_create (&key, destr) != 0)
  50. {
  51. puts ("key_create 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. if (pthread_join (th, NULL) != 0)
  61. {
  62. puts ("join failed");
  63. return 1;
  64. }
  65. if (rounds < PTHREAD_DESTRUCTOR_ITERATIONS)
  66. {
  67. printf ("rounds == %d, PTHREAD_DESTRUCTOR_ITERATIONS = %d\n",
  68. rounds, PTHREAD_DESTRUCTOR_ITERATIONS);
  69. return 1;
  70. }
  71. if (pthread_getspecific (key) != NULL)
  72. {
  73. puts ("key data != NULL");
  74. return 1;
  75. }
  76. return 0;
  77. }
  78. #define TEST_FUNCTION do_test ()
  79. #include "../test-skeleton.c"