test-with-guile-module.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 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. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include <pthread.h>
  22. #include <libguile.h>
  23. void *thread_inner_main (void *unused);
  24. void *thread_main (void *unused);
  25. void *do_join (void *data);
  26. void *inner_main (void *unused);
  27. void *
  28. thread_inner_main (void *unused)
  29. {
  30. int argc = 3;
  31. char *argv[] = {
  32. "guile",
  33. "-c",
  34. "(or (current-module) (exit -1))",
  35. 0
  36. };
  37. scm_shell (argc, argv);
  38. return NULL; /* dummy */
  39. }
  40. void *
  41. thread_main (void *unused)
  42. {
  43. scm_with_guile (&thread_inner_main, NULL);
  44. return NULL; /* dummy */
  45. }
  46. void *
  47. do_join (void *data)
  48. {
  49. pthread_t *thread = (pthread_t *) data;
  50. pthread_join (*thread, NULL);
  51. return NULL; /* dummy */
  52. }
  53. void *
  54. inner_main (void *unused)
  55. {
  56. pthread_t thread;
  57. pthread_create (&thread, NULL, &thread_main, NULL);
  58. scm_without_guile (do_join, &thread);
  59. return NULL; /* dummy */
  60. }
  61. int
  62. main (int argc, char **argv)
  63. {
  64. scm_with_guile (&inner_main, NULL);
  65. return 0;
  66. }