tests: Skip `test-pthread-create-secondary' except on Linux-based systems.
[bpt/guile.git] / test-suite / standalone / test-pthread-create-secondary.c
CommitLineData
4702deb4 1/* Copyright (C) 2011, 2013 Free Software Foundation, Inc.
4a235623
LC
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 threads created with `pthread_create' work, and whether
20 a secondary thread can call `scm_with_guile'. (bug #32436). */
21
22#ifdef HAVE_CONFIG_H
23# include <config.h>
24#endif
25
26#include <pthread.h>
27#include <stdlib.h>
28#include <libguile.h>
29
8f47877f 30#include <gc/gc.h>
4a235623
LC
31
32
4702deb4
LC
33/* Currently, calling `GC_INIT' from a secondary thread is only
34 supported on some systems, notably Linux-based systems (and not on
35 FreeBSD, for instance.)
36
37 Up to GC 7.2alpha5, calling `GC_INIT' from a secondary thread would
4a235623
LC
38 lead to a segfault. This was fixed in BDW-GC on 2011-04-16 by Ivan
39 Maidanski. See <http://thread.gmane.org/gmane.lisp.guile.bugs/5340>
40 for details. */
41
4702deb4
LC
42#if defined __linux__ \
43 && (GC_VERSION_MAJOR > 7 \
44 || (GC_VERSION_MAJOR == 7 && GC_VERSION_MINOR > 2) \
45 || (GC_VERSION_MAJOR == 7 && GC_VERSION_MINOR == 2 \
46 && GC_ALPHA_VERSION > 5))
4a235623
LC
47
48static void *
49do_something (void *arg)
50{
51 scm_list_copy (scm_make_list (scm_from_int (1234), SCM_BOOL_T));
52 scm_gc ();
53 return NULL;
54}
55
56static void *
57thread (void *arg)
58{
59 scm_with_guile (do_something, NULL);
60 return NULL;
61}
62
63\f
64int
65main (int argc, char *argv[])
66{
67 int i;
68
69 for (i = 0; i < 77; i++)
70 {
71 pthread_t thr;
72
73 pthread_create (&thr, NULL, thread, NULL);
74 pthread_join (thr, NULL);
75 }
76
77 return EXIT_SUCCESS;
78}
79
80\f
4702deb4 81#else /* Linux && GC < 7.2alpha5 */
4a235623
LC
82
83int
84main (int argc, char *argv[])
85{
86 /* Skip. */
87 return 77;
88}
89
90#endif /* GC < 7.2 */