tst-kill4.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <errno.h>
  16. #include <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. static void *
  22. tf (void *a)
  23. {
  24. return NULL;
  25. }
  26. int
  27. do_test (void)
  28. {
  29. pthread_t th;
  30. if (pthread_create (&th, NULL, tf, NULL) != 0)
  31. {
  32. puts ("create failed");
  33. exit (1);
  34. }
  35. if (pthread_join (th, NULL) != 0)
  36. {
  37. puts ("join failed");
  38. exit (1);
  39. }
  40. /* The following only works because we assume here something about
  41. the implementation. Namely, that the memory allocated for the
  42. thread descriptor is not going away, that the the TID field is
  43. cleared and therefore the signal is sent to process 0, and that
  44. we can savely assume there is no other process with this ID at
  45. that time. */
  46. int e = pthread_kill (th, 0);
  47. if (e == 0)
  48. {
  49. puts ("pthread_kill succeeded");
  50. exit (1);
  51. }
  52. if (e != ESRCH)
  53. {
  54. puts ("pthread_kill didn't return ESRCH");
  55. exit (1);
  56. }
  57. return 0;
  58. }
  59. #define TEST_FUNCTION do_test ()
  60. #include "../test-skeleton.c"