bug#79100: segfault with thread initialization

a aa <[email protected]> Sat, 26 Jul 2025 00:05:46 +0000
Newsgroups gmane.lisp.guile.bugs
Message-ID <CAN=a0HpjcK6pHGrcDWZre5jxxLpN9_p_TT+QkvyZ0XLwp_rNUg@mail.gmail.com>
--000000000000b0c2fd063ac9d222
Content-Type: text/plain; charset="UTF-8"

# version
3.0.10

# `config.guess`
x86_64-pc-linux-gnu

# `config.status`
`--prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share
--sysconfdir=/etc --localstatedir=/var/lib --datarootdir=/usr/share
--disable-dependency-tracking --disable-silent-rules --disable-static
--docdir=/usr/share/doc/guile-3.0.10-r103
--htmldir=/usr/share/doc/guile-3.0.10-r103/html --with-sysroot=/
--libdir=/usr/lib64 --program-suffix=-3.0
--infodir=/usr/share/guile-data/3.0/info
--with-pkgconfigdir=/usr/share/guile-data/3.0/pkgconfig
--disable-error-on-warning --disable-rpath --disable-lto --enable-posix
--without-libgmp-prefix --without-libiconv-prefix --without-libintl-prefix
--without-libreadline-prefix --without-libunistring-prefix
--disable-guile-debug --disable-debug-malloc --enable-deprecated
--enable-jit --enable-networking --disable-nls --enable-regex
--with-threads build_alias=x86_64-pc-linux-gnu
host_alias=x86_64-pc-linux-gnu CC=gcc 'CFLAGS=-O2 -march=native -pipe
-std=gnu17' LDFLAGS=-fuse-ld=mold
PKG_CONFIG_PATH=/usr/share/guile-data/3.0/pkgconfig`

# How to reproduce
```c
#include <libguile.h>
#include <pthread.h>

void* foo(void*) {
    return NULL;
}

void* run_with_guile(void*)
{
    scm_with_guile(foo, NULL);
    return NULL;
}

int main(void)
{
    pthread_t thread_1, thread_2;
    pthread_create(&thread_1, NULL, run_with_guile, NULL);
    pthread_create(&thread_2, NULL, run_with_guile, NULL);

    pthread_join(thread_1, NULL);
    pthread_join(thread_2, NULL);
    return 0;
}
```

## Output
```txt
Segmentation fault
```

# Intended behaviour
According to the [documentation](
https://www.gnu.org/software/guile/manual/html_node/Guile-Initialization-Functions.html),
you should be able to call `scm_with_guile` concurrently.

--000000000000b0c2fd063ac9d222
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"># version<br>3.0.10<br><br># `config.guess`<br>x86_64-pc-l=
inux-gnu<br><br># `config.status`<br>`--prefix=3D/usr --build=3Dx86_64-pc-l=
inux-gnu --host=3Dx86_64-pc-linux-gnu --mandir=3D/usr/share/man --infodir=
=3D/usr/share/info --datadir=3D/usr/share --sysconfdir=3D/etc --localstated=
ir=3D/var/lib --datarootdir=3D/usr/share --disable-dependency-tracking --di=
sable-silent-rules --disable-static --docdir=3D/usr/share/doc/guile-3.0.10-=
r103 --htmldir=3D/usr/share/doc/guile-3.0.10-r103/html --with-sysroot=3D/ -=
-libdir=3D/usr/lib64 --program-suffix=3D-3.0 --infodir=3D/usr/share/guile-d=
ata/3.0/info --with-pkgconfigdir=3D/usr/share/guile-data/3.0/pkgconfig --di=
sable-error-on-warning --disable-rpath --disable-lto --enable-posix --witho=
ut-libgmp-prefix --without-libiconv-prefix --without-libintl-prefix --witho=
ut-libreadline-prefix --without-libunistring-prefix --disable-guile-debug -=
-disable-debug-malloc --enable-deprecated --enable-jit --enable-networking =
--disable-nls --enable-regex --with-threads build_alias=3Dx86_64-pc-linux-g=
nu host_alias=3Dx86_64-pc-linux-gnu CC=3Dgcc &#39;CFLAGS=3D-O2 -march=3Dnat=
ive -pipe -std=3Dgnu17&#39; LDFLAGS=3D-fuse-ld=3Dmold PKG_CONFIG_PATH=3D/us=
r/share/guile-data/3.0/pkgconfig`<br><br># How to reproduce<br>```c<br>#inc=
lude &lt;libguile.h&gt;<br>#include &lt;pthread.h&gt;<br><br>void* foo(void=
*) {<br>=C2=A0 =C2=A0 return NULL;<br>}<br><br>void* run_with_guile(void*)<=
br>{<br>=C2=A0 =C2=A0 scm_with_guile(foo, NULL);<br>=C2=A0 =C2=A0 return NU=
LL;<br>}<br><br>int main(void)<br>{<br>=C2=A0 =C2=A0 pthread_t thread_1, th=
read_2;<br>=C2=A0 =C2=A0 pthread_create(&amp;thread_1, NULL, run_with_guile=
, NULL);<br>=C2=A0 =C2=A0 pthread_create(&amp;thread_2, NULL, run_with_guil=
e, NULL);<br>=C2=A0 =C2=A0 <br>=C2=A0 =C2=A0 pthread_join(thread_1, NULL);<=
br>=C2=A0 =C2=A0 pthread_join(thread_2, NULL);<br>=C2=A0 =C2=A0 return 0;<b=
r>}<br>```<br><br>## Output<br>```txt<br>Segmentation fault<br>```<br><br>#=
 Intended behaviour<br>According to the [documentation](<a href=3D"https://=
www.gnu.org/software/guile/manual/html_node/Guile-Initialization-Functions.=
html">https://www.gnu.org/software/guile/manual/html_node/Guile-Initializat=
ion-Functions.html</a>), you should be able to call `scm_with_guile` concur=
rently.</div>

--000000000000b0c2fd063ac9d222--