tst-basic3.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. static int nrunning = 1;
  22. static void
  23. final_test (void)
  24. {
  25. puts ("final_test has been called");
  26. #define THE_SIGNAL SIGUSR1
  27. kill (getpid (), SIGUSR1);
  28. }
  29. static void *
  30. tf (void *a)
  31. {
  32. if (pthread_join ((pthread_t) a, NULL) != 0)
  33. {
  34. printf ("join failed while %d are running\n", nrunning);
  35. _exit (1);
  36. }
  37. printf ("%2d left\n", --nrunning);
  38. return NULL;
  39. }
  40. int
  41. do_test (void)
  42. {
  43. #define N 20
  44. pthread_t t[N];
  45. pthread_t last = pthread_self ();
  46. int i;
  47. atexit (final_test);
  48. printf ("starting %d + 1 threads\n", N);
  49. for (i = 0; i < N; ++i)
  50. {
  51. if (pthread_create (&t[i], NULL, tf, (void *) last) != 0)
  52. {
  53. puts ("create failed");
  54. _exit (1);
  55. }
  56. ++nrunning;
  57. last = t[i];
  58. }
  59. printf ("%2d left\n", --nrunning);
  60. pthread_exit (NULL);
  61. }
  62. #define EXPECTED_SIGNAL THE_SIGNAL
  63. #define TEST_FUNCTION do_test ()
  64. #include "../test-skeleton.c"