test-scm-spawn-thread.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright 2011-2012,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* Test whether a thread created with `scm_spawn_thread' can be joined.
  16. See <http://thread.gmane.org/gmane.lisp.guile.devel/11804> for the
  17. original report. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include <libguile.h>
  22. #include <time.h>
  23. #include <stdlib.h>
  24. static SCM
  25. thread_main (void *data)
  26. {
  27. return SCM_BOOL_T;
  28. }
  29. static SCM
  30. thread_handler (void *data, SCM key, SCM args)
  31. {
  32. return SCM_BOOL_T;
  33. }
  34. static void *
  35. inner_main (void *data)
  36. {
  37. SCM thread, timeout;
  38. thread = scm_spawn_thread (thread_main, 0, thread_handler, 0);
  39. timeout = scm_from_unsigned_integer (time (NULL) + 10);
  40. return SCM2PTR (scm_join_thread_timed (thread, timeout, SCM_BOOL_F));
  41. }
  42. int
  43. main (int argc, char **argv)
  44. {
  45. SCM result;
  46. result = PTR2SCM (scm_with_guile (inner_main, 0));
  47. return scm_is_true (result) ? EXIT_SUCCESS : EXIT_FAILURE;
  48. }