reconnect-signal.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* This testcase is part of GDB, the GNU debugger.
  2. Copyright 2013-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 <signal.h>
  15. #include <unistd.h>
  16. static pthread_t thread_2;
  17. sig_atomic_t unlocked;
  18. /* The test has three threads, and it's always thread 2 that gets the
  19. signal, to avoid spurious passes in case the remote side happens to
  20. always pick the first or the last thread in the list as the
  21. current/status thread on reconnection. */
  22. static void *
  23. start2 (void *arg)
  24. {
  25. unsigned int count;
  26. pthread_kill (thread_2, SIGUSR1);
  27. for (count = 1; !unlocked && count != 0; count++)
  28. usleep (1);
  29. return NULL;
  30. }
  31. static void *
  32. start (void *arg)
  33. {
  34. pthread_t thread;
  35. pthread_create (&thread, NULL, start2, NULL);
  36. pthread_join (thread, NULL);
  37. return NULL;
  38. }
  39. void
  40. handle (int sig)
  41. {
  42. unlocked = 1;
  43. }
  44. int
  45. main ()
  46. {
  47. signal (SIGUSR1, handle);
  48. pthread_create (&thread_2, NULL, start, NULL);
  49. pthread_join (thread_2, NULL);
  50. return 0;
  51. }