tst-exit3.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <pthread.h>
  2. #include <signal.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. static pthread_barrier_t b;
  8. static void *
  9. tf2 (void *arg)
  10. {
  11. while (1)
  12. sleep (100);
  13. /* NOTREACHED */
  14. return NULL;
  15. }
  16. static void *
  17. tf (void *arg)
  18. {
  19. pthread_t th;
  20. int e = pthread_barrier_wait (&b);
  21. if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
  22. {
  23. puts ("barrier_wait failed");
  24. exit (1);
  25. }
  26. e = pthread_create (&th, NULL, tf2, NULL);
  27. if (e != 0)
  28. {
  29. printf ("create failed: %s\n", strerror (e));
  30. exit (1);
  31. }
  32. /* Terminate only this thread. */
  33. return NULL;
  34. }
  35. static int
  36. do_test (void)
  37. {
  38. pthread_t th;
  39. if (pthread_barrier_init (&b, NULL, 2) != 0)
  40. {
  41. puts ("barrier_init failed");
  42. exit (1);
  43. }
  44. int e = pthread_create (&th, NULL, tf, NULL);
  45. if (e != 0)
  46. {
  47. printf ("create failed: %s\n", strerror (e));
  48. exit (1);
  49. }
  50. e = pthread_barrier_wait (&b);
  51. if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
  52. {
  53. puts ("barrier_wait failed");
  54. exit (1);
  55. }
  56. /* Terminate only this thread. */
  57. pthread_exit (NULL);
  58. /* NOTREACHED */
  59. return 1;
  60. }
  61. #define EXPECTED_SIGNAL SIGALRM
  62. #define TEST_FUNCTION do_test ()
  63. #include "../test-skeleton.c"