1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00

Exclude the finalizer thread from the ‘all-threads’ result.

Fixes <https://bugs.gnu.org/76343>.

Fixes a bug whereby “echo '(environ)' | guile” would wrongfully trigger
the multiple-thread warning.

* libguile/finalizers.c (finalizer_thread): New variable.
(finalization_thread_proc): Set it.
(scm_i_is_finalizer_thread): New function.
(run_finalization_thread): Clear FINALIZER_THREAD.
* libguile/finalizers.h (scm_i_is_finalizer_thread): New declaration.
* libguile/threads.c (scm_all_threads): Use it.
* NEWS: Update.

Reported-by: Simon Josefsson <simon@josefsson.org>
This commit is contained in:
Ludovic Courtès 2025-02-26 15:48:41 +01:00
parent 75fd1d6434
commit b8031fc965
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
4 changed files with 34 additions and 7 deletions

8
NEWS
View file

@ -1,5 +1,5 @@
Guile NEWS --- history of user-visible changes. Guile NEWS --- history of user-visible changes.
Copyright (C) 1996-2024 Free Software Foundation, Inc. Copyright (C) 1996-2025 Free Software Foundation, Inc.
See the end for copying conditions. See the end for copying conditions.
Please send Guile bug reports to bug-guile@gnu.org. Please send Guile bug reports to bug-guile@gnu.org.
@ -80,6 +80,12 @@ every line in a file.
(<https://bugs.gnu.org/75642>) (<https://bugs.gnu.org/75642>)
** Change <libguile/scm.h> to allow compilation with -Werror=undef ** Change <libguile/scm.h> to allow compilation with -Werror=undef
(<https://bugs.gnu.org/75085>) (<https://bugs.gnu.org/75085>)
** 'all-threads' no longer includes the finalizer thread
(<https://bugs.gnu.org/76343>)
Previously 'all-threads' would include the finalizer thread. This,
in turn, would trigger warnings from 'primitive-fork' and 'environ'
suggesting they are being called in a multi-threaded context, when in
fact user code did not create any thread.
Changes in 3.0.10 (since 3.0.9) Changes in 3.0.10 (since 3.0.9)

View file

@ -1,4 +1,4 @@
/* Copyright 2012-2014,2018-2020,2022 /* Copyright 2012-2014,2018-2020,2022,2025
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of Guile. This file is part of Guile.
@ -37,6 +37,7 @@
#include "gsubr.h" #include "gsubr.h"
#include "init.h" #include "init.h"
#include "threads.h" #include "threads.h"
#include "atomics-internal.h"
#include "finalizers.h" #include "finalizers.h"
@ -217,10 +218,14 @@ read_finalization_pipe_data (void *data)
return NULL; return NULL;
} }
static scm_i_pthread_t finalizer_thread;
static void* static void*
finalization_thread_proc (void *unused) finalization_thread_proc (void *unused)
{ {
scm_atomic_set_pointer ((void **) &finalizer_thread,
(void *) pthread_self ());
while (1) while (1)
{ {
struct finalization_pipe_data data; struct finalization_pipe_data data;
@ -255,10 +260,20 @@ finalization_thread_proc (void *unused)
} }
} }
int
scm_i_is_finalizer_thread (struct scm_thread *t)
{
scm_i_pthread_t us =
(scm_i_pthread_t) scm_atomic_ref_pointer ((void **) &finalizer_thread);
return pthread_equal (t->pthread, us);
}
static void* static void*
run_finalization_thread (void *arg) run_finalization_thread (void *arg)
{ {
return scm_with_guile (finalization_thread_proc, arg); void *res = scm_with_guile (finalization_thread_proc, arg);
scm_atomic_set_pointer ((void **) &finalizer_thread, NULL);
return res;
} }
static void static void

View file

@ -1,7 +1,7 @@
#ifndef SCM_FINALIZERS_H #ifndef SCM_FINALIZERS_H
#define SCM_FINALIZERS_H #define SCM_FINALIZERS_H
/* Copyright 2012, 2013, 2014, 2018 /* Copyright 2012, 2013, 2014, 2018, 2025
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of Guile. This file is part of Guile.
@ -42,6 +42,9 @@ SCM_INTERNAL void scm_i_finalizer_pre_fork (void);
thread. */ thread. */
SCM_INTERNAL void scm_i_register_async_gc_callback (void (*callback) (void)); SCM_INTERNAL void scm_i_register_async_gc_callback (void (*callback) (void));
/* Return true if THREAD is the finalizer thread. */
SCM_INTERNAL int scm_i_is_finalizer_thread (struct scm_thread *thread);
SCM_API int scm_set_automatic_finalization_enabled (int enabled_p); SCM_API int scm_set_automatic_finalization_enabled (int enabled_p);
SCM_API int scm_run_finalizers (void); SCM_API int scm_run_finalizers (void);

View file

@ -1,4 +1,4 @@
/* Copyright 1995-1998,2000-2014,2018-2019,2023-2024 /* Copyright 1995-1998,2000-2014,2018-2019,2023-2025
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of Guile. This file is part of Guile.
@ -47,6 +47,7 @@
#include "dynwind.h" #include "dynwind.h"
#include "eval.h" #include "eval.h"
#include "extensions.h" #include "extensions.h"
#include "finalizers.h"
#include "fluids.h" #include "fluids.h"
#include "gc-inline.h" #include "gc-inline.h"
#include "gc.h" #include "gc.h"
@ -1691,7 +1692,9 @@ SCM_DEFINE (scm_all_threads, "all-threads", 0, 0, 0,
for (t = all_threads; t && n > 0; t = t->next_thread) for (t = all_threads; t && n > 0; t = t->next_thread)
{ {
if (!t->exited && !scm_i_is_signal_delivery_thread (t)) if (!t->exited
&& !scm_i_is_signal_delivery_thread (t)
&& !scm_i_is_finalizer_thread (t))
{ {
SCM_SETCAR (*l, t->handle); SCM_SETCAR (*l, t->handle);
l = SCM_CDRLOC (*l); l = SCM_CDRLOC (*l);