kill.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* This testcase is part of GDB, the GNU debugger.
  2. Copyright 2014-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifdef USE_THREADS
  14. #include <unistd.h>
  15. #include <pthread.h>
  16. #define NUM 5
  17. pthread_barrier_t barrier;
  18. void *
  19. thread_function (void *arg)
  20. {
  21. volatile unsigned int counter = 1;
  22. pthread_barrier_wait (&barrier);
  23. while (counter > 0)
  24. {
  25. counter++;
  26. usleep (1);
  27. }
  28. pthread_exit (NULL);
  29. }
  30. #endif /* USE_THREADS */
  31. void
  32. setup (void)
  33. {
  34. #ifdef USE_THREADS
  35. pthread_t threads[NUM];
  36. int i;
  37. pthread_barrier_init (&barrier, NULL, NUM + 1);
  38. for (i = 0; i < NUM; i++)
  39. pthread_create (&threads[i], NULL, thread_function, NULL);
  40. pthread_barrier_wait (&barrier);
  41. #endif /* USE_THREADS */
  42. }
  43. int
  44. main (void)
  45. {
  46. setup ();
  47. return 0; /* set break here */
  48. }