tst-kill1.c 2.4 KB

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