tst-kill1.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
  20. static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
  21. static pthread_barrier_t b;
  22. static void *
  23. tf (void *a)
  24. {
  25. if (pthread_mutex_lock (&m) != 0)
  26. {
  27. puts ("child: mutex_lock failed");
  28. exit (1);
  29. }
  30. int e = pthread_barrier_wait (&b);
  31. if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
  32. {
  33. puts ("child: barrier_wait failed");
  34. exit (1);
  35. }
  36. /* This call should never return. */
  37. pthread_cond_wait (&c, &m);
  38. return NULL;
  39. }
  40. int
  41. do_test (void)
  42. {
  43. pthread_t th;
  44. if (pthread_barrier_init (&b, NULL, 2) != 0)
  45. {
  46. puts ("barrier_init failed");
  47. exit (1);
  48. }
  49. if (pthread_create (&th, NULL, tf, NULL) != 0)
  50. {
  51. puts ("create failed");
  52. exit (1);
  53. }
  54. int e = pthread_barrier_wait (&b);
  55. if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
  56. {
  57. puts ("barrier_wait failed");
  58. exit (1);
  59. }
  60. if (pthread_mutex_lock (&m) != 0)
  61. {
  62. puts ("mutex_lock failed");
  63. exit (1);
  64. }
  65. /* Send the thread a signal which it doesn't catch and which will
  66. cause the process to terminate. */
  67. if (pthread_kill (th, SIGUSR1) != 0)
  68. {
  69. puts ("kill failed");
  70. exit (1);
  71. }
  72. /* This call should never return. */
  73. pthread_join (th, NULL);
  74. return 0;
  75. }
  76. #define EXPECTED_SIGNAL SIGUSR1
  77. #define TEST_FUNCTION do_test ()
  78. #include "../test-skeleton.c"