Merge commit 'fb7dd00169304a5922838e4d2f25253640a35def'
[bpt/guile.git] / test-suite / standalone / test-scm-spawn-thread.c
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
19 /* Test whether a thread created with `scm_spawn_thread' can be joined.
20 See <http://thread.gmane.org/gmane.lisp.guile.devel/11804> for the
21 original report. */
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <libguile.h>
28
29 #include <time.h>
30 #include <stdlib.h>
31
32 static SCM
33 thread_main (void *data)
34 {
35 return SCM_BOOL_T;
36 }
37
38 static SCM
39 thread_handler (void *data, SCM key, SCM args)
40 {
41 return SCM_BOOL_T;
42 }
43
44 static void *
45 inner_main (void *data)
46 {
47 SCM thread, timeout;
48
49 thread = scm_spawn_thread (thread_main, 0, thread_handler, 0);
50 timeout = scm_from_unsigned_integer (time (NULL) + 10);
51 return SCM2PTR (scm_join_thread_timed (thread, timeout, SCM_BOOL_F));
52 }
53
54 \f
55 int
56 main (int argc, char **argv)
57 {
58 SCM result;
59
60 result = PTR2SCM (scm_with_guile (inner_main, 0));
61 return scm_is_true (result) ? EXIT_SUCCESS : EXIT_FAILURE;
62 }