GNU bug report logs -
#36609
27.0.50; Possible race-condition in threading implementation
Previous Next
Reported by: Andreas Politz <politza <at> hochschule-trier.de>
Date: Thu, 11 Jul 2019 20:52:02 UTC
Severity: normal
Tags: fixed
Found in version 27.0.50
Fixed in version 28.1
Done: dick <dick.r.chiang <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #168 received at 36609 <at> debbugs.gnu.org (full text, mbox):
> From: dick.r.chiang <at> gmail.com
> Cc: 36609 <at> debbugs.gnu.org
> Date: Sun, 20 Jun 2021 10:01:37 -0400
>
> Yes! If you just add a negation to the __atomic_sub_fetch call
You mean, use the patch below instead?
> this passes all the MREs.
Thanks, will install soon.
> It's not clear how you want to deal with the #else GNUC_PREREQ (4, 7, 0).
By hoping no one uses this and expects threads to be stable enough
under GTK.
diff --git a/src/xgselect.c b/src/xgselect.c
index 0d91d55bad..92b118b955 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -34,12 +34,27 @@ static GMainContext *glib_main_context;
void release_select_lock (void)
{
+#if GNUC_PREREQ (4, 7, 0)
+ if (__atomic_sub_fetch (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL) == 0)
+ g_main_context_release (glib_main_context);
+#else
if (--threads_holding_glib_lock == 0)
g_main_context_release (glib_main_context);
+#endif
}
static void acquire_select_lock (GMainContext *context)
{
+#if GNUC_PREREQ (4, 7, 0)
+ if (__atomic_fetch_add (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL) == 0)
+ {
+ glib_main_context = context;
+ while (!g_main_context_acquire (context))
+ {
+ /* Spin. */
+ }
+ }
+#else
if (threads_holding_glib_lock++ == 0)
{
glib_main_context = context;
@@ -48,6 +63,7 @@ static void acquire_select_lock (GMainContext *context)
/* Spin. */
}
}
+#endif
}
/* `xg_select' is a `pselect' replacement. Why do we need a separate function?
This bug report was last modified 4 years and 27 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.