test-with-guile-module.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 2008 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
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This 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. *
  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 02110-1301 USA
  16. */
  17. #ifndef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include <pthread.h>
  21. #include <libguile.h>
  22. void *thread_inner_main (void *unused);
  23. void *thread_main (void *unused);
  24. void *do_join (void *data);
  25. void *inner_main (void *unused);
  26. void *
  27. thread_inner_main (void *unused)
  28. {
  29. int argc = 3;
  30. char *argv[] = {
  31. "guile",
  32. "-c",
  33. "(or (current-module) (exit -1))",
  34. 0
  35. };
  36. scm_shell (argc, argv);
  37. return NULL; /* dummy */
  38. }
  39. void *
  40. thread_main (void *unused)
  41. {
  42. scm_with_guile (&thread_inner_main, NULL);
  43. return NULL; /* dummy */
  44. }
  45. void *
  46. do_join (void *data)
  47. {
  48. pthread_t *thread = (pthread_t *) data;
  49. pthread_join (*thread, NULL);
  50. return NULL; /* dummy */
  51. }
  52. void *
  53. inner_main (void *unused)
  54. {
  55. pthread_t thread;
  56. pthread_create (&thread, NULL, &thread_main, NULL);
  57. scm_without_guile (do_join, &thread);
  58. return NULL; /* dummy */
  59. }
  60. int
  61. main (int argc, char **argv)
  62. {
  63. scm_with_guile (&inner_main, NULL);
  64. return 0;
  65. }