test-with-guile-module.c 1.7 KB

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