test-scm-spawn-thread.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * 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. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. /* Test whether a thread created with `scm_spawn_thread' can be joined.
  19. See <http://thread.gmane.org/gmane.lisp.guile.devel/11804> for the
  20. original report. */
  21. #ifdef HAVE_CONFIG_H
  22. # include <config.h>
  23. #endif
  24. #include <libguile.h>
  25. #include <time.h>
  26. #include <stdlib.h>
  27. static SCM
  28. thread_main (void *data)
  29. {
  30. return SCM_BOOL_T;
  31. }
  32. static SCM
  33. thread_handler (void *data, SCM key, SCM args)
  34. {
  35. return SCM_BOOL_T;
  36. }
  37. static void *
  38. inner_main (void *data)
  39. {
  40. SCM thread, timeout;
  41. thread = scm_spawn_thread (thread_main, 0, thread_handler, 0);
  42. timeout = scm_from_unsigned_integer (time (NULL) + 10);
  43. return SCM2PTR (scm_join_thread_timed (thread, timeout, SCM_BOOL_F));
  44. }
  45. int
  46. main (int argc, char **argv)
  47. {
  48. SCM result;
  49. result = PTR2SCM (scm_with_guile (inner_main, 0));
  50. return scm_is_true (result) ? EXIT_SUCCESS : EXIT_FAILURE;
  51. }