interrupt-while-step-over.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* This testcase is part of GDB, the GNU debugger.
  2. Copyright 2016-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. #include <pthread.h>
  14. #include <unistd.h>
  15. #include <stdlib.h>
  16. #define NUM_THREADS 20
  17. const int num_threads = NUM_THREADS;
  18. static pthread_t child_thread[NUM_THREADS];
  19. static pthread_barrier_t threads_started_barrier;
  20. volatile int always_zero;
  21. volatile unsigned int dummy;
  22. static void
  23. infinite_loop (void)
  24. {
  25. while (1)
  26. {
  27. dummy++; /* set breakpoint here */
  28. }
  29. }
  30. static void *
  31. child_function (void *arg)
  32. {
  33. pthread_barrier_wait (&threads_started_barrier);
  34. infinite_loop ();
  35. return NULL;
  36. }
  37. void
  38. all_started (void)
  39. {
  40. }
  41. int
  42. main (void)
  43. {
  44. int res;
  45. int i;
  46. alarm (300);
  47. pthread_barrier_init (&threads_started_barrier, NULL, NUM_THREADS + 1);
  48. for (i = 0; i < NUM_THREADS; i++)
  49. {
  50. res = pthread_create (&child_thread[i], NULL, child_function, NULL);
  51. }
  52. /* Wait until all threads have been scheduled. */
  53. pthread_barrier_wait (&threads_started_barrier);
  54. all_started ();
  55. infinite_loop ();
  56. }