tst-cond-deadlock.c 937 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2016 Martin Willi <martin@strongswan.org>
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. #include <pthread.h>
  6. static pthread_mutex_t m;
  7. static pthread_cond_t c;
  8. static pthread_t t;
  9. static volatile int ready;
  10. static void cancelcb(void *arg)
  11. {
  12. pthread_mutex_unlock(&m);
  13. }
  14. static void* threadcb(void *arg)
  15. {
  16. pthread_mutex_lock(&m);
  17. pthread_cleanup_push(cancelcb, NULL);
  18. ready = 1;
  19. while (1)
  20. pthread_cond_wait(&c, &m);
  21. pthread_cleanup_pop(1);
  22. }
  23. static int
  24. do_test (void)
  25. {
  26. pthread_mutex_init(&m, NULL);
  27. pthread_cond_init(&c, NULL);
  28. pthread_create(&t, NULL, threadcb, NULL);
  29. while (!ready);
  30. pthread_cancel(t);
  31. pthread_join(t, NULL);
  32. pthread_cond_signal(&c);
  33. pthread_cond_destroy(&c);
  34. pthread_mutex_destroy(&m);
  35. return 0;
  36. }
  37. #define TEST_FUNCTION do_test ()
  38. #define TIMEOUT 100
  39. #include "../test-skeleton.c"