Merge branch 'stable-2.0'
[bpt/guile.git] / test-suite / standalone / test-with-guile-module.c
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
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <pthread.h>
24 #include <libguile.h>
25
26 void *thread_inner_main (void *unused);
27 void *thread_main (void *unused);
28 void *do_join (void *data);
29 void *inner_main (void *unused);
30
31 void *
32 thread_inner_main (void *unused)
33 {
34 int argc = 3;
35 char *argv[] = {
36 "guile",
37 "-c",
38 "(or (current-module) (exit -1))",
39 0
40 };
41
42 scm_shell (argc, argv);
43
44 return NULL; /* dummy */
45 }
46
47 void *
48 thread_main (void *unused)
49 {
50 scm_with_guile (&thread_inner_main, NULL);
51
52 return NULL; /* dummy */
53 }
54
55 void *
56 do_join (void *data)
57 {
58 pthread_t *thread = (pthread_t *) data;
59
60 pthread_join (*thread, NULL);
61
62 return NULL; /* dummy */
63 }
64
65 void *
66 inner_main (void *unused)
67 {
68 pthread_t thread;
69
70 pthread_create (&thread, NULL, &thread_main, NULL);
71 scm_without_guile (do_join, &thread);
72
73 return NULL; /* dummy */
74 }
75
76 int
77 main (int argc, char **argv)
78 {
79 scm_with_guile (&inner_main, NULL);
80
81 return 0;
82 }