tst-basic3.c 1.8 KB

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