delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/11/05/09:02:13

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5A5E2CaF2507725
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 5A5E2CaF2507725
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=pFRbRW5f
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF8813857348
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1762351331;
bh=jXB58OlFXWxuXjaf+pkVFPnaiYAIQcl2Bx/dMsp+QQY=;
h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:From;
b=pFRbRW5fZX+P6GzvPj+vXiy4+IMk+Pp1mceabdUNtwZgVxCOeQiVM2qDA/Y45or5s
OG5+ZG8p91QzeDic21QMr1PvTrIS9GKjnN0WTDGZfPSP/gGGCz8yOrjqy1Ig7DBKKF
uoq+y+Obl2vU2lc1cj7wqjOLqPYYK05GSJF5Nmr0=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDBDB3857348
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EDBDB3857348
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1762351248; cv=none;
b=PdSOx5Q/qTBZQoU4i6SymgTVMs1bWBhKdLBu1Fh5ZAxB95x9a8rKW1/XnukN2ZMXquS3J/TJBaOczzIOn4cEdSSAK19K6UNk2VbATQbq2ZW3aak2D7teOIZqUG2Jlmg9H2sQAW2XECUKy9h/V22xGODFmRPcBk9ldVQaiwXYofA=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1762351248; c=relaxed/simple;
bh=65fSMvVIFP0pPr2AXbbxo5goSTp3uob/i7q0chJHijM=;
h=DKIM-Signature:Message-Id:From:To:Subject:Date:MIME-Version;
b=Cv2IsC9rVIq7rkis3yVzsU9rXN2zqUDNVUErhN+MDBtS6w4wtENy4vDCBBtUMMZvD13c9DhuuQ1e+CdYKqRmARJ3ypzB1Xzms8N4SDIr1llVCE7CUWyVQ3FoxCVeHjzEKp5kcbRYo2yyomc9lZhJjDevFoT4adcaSDTDBsibIeA=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDBDB3857348
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1762351247; x=1762956047;
h=mime-version:content-transfer-encoding:user-agent:date:subject:to
:from:message-id:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to;
bh=eFIUXXdt2Y2C3ZsqmJ00T+3O4dB3KIjodHGfqOnwN/s=;
b=WNq8JJKt+F1mTyWamJmOFRhPZK4VfdJC8rbRdTspBmVIPU336I0SQimLEd/bvQ9nvO
qezodAxBp2NbMKG5iARWHwv9OiinC+TeBx29CsTVo8ctGjUwU3YT/DJm6c5wwIAAvOiV
BkLvJHoPZsq/7AMwRfR1fAeK2seZwYmKSw/eS+NpVTuMz0wV1HM7gQgsckxlZvyCzBYs
jdKJ/OicXC8o/BlXogDQ0mMK3dCXrTbLjXNi7JVgFvP3o0MZ9Gxp0sq8v7cHAJ49zhxu
av+5N/oI50upZMY35yjDm9UtClatJkb2S7Uz5QwXujGPGF8ltc/VvzjkP+fhRif3NJ67
IpTg==
X-Forwarded-Encrypted: i=1;
AJvYcCVs55ARBPdL5ZPmfVJoJ45bMMj1nPSGLYigFDosGwnccUeYiiTHqfw0r+GiVstbEu1SLINods8=@cygwin.com
X-Gm-Message-State: AOJu0YwVRem0H3HEx+Kw7NWhUP14WnYHywrNIHe0u9S1LrTktMeFBiNV
EaDNb1FTIbRK/xSOrqSexpQXa/CNECRWTlZOLcFudr1r3O0GHTrtV1x1VaQ49gULAes=
X-Gm-Gg: ASbGnctz7vo3U9m3fpuK/9W2i4Fk3GQpX51z8DniEhtDizaPE70kZRTr1637DkM63qV
9WLicxYFu6Ujwz/qMHK5YhgpAks9WZZWT6B0DU5d9tkT+wozdYwq48l4f6c+M2FJu4wRu784LPQ
qqDUTvPE7uzzOSMUt3LHc9OXWGHLgrkkr0xt8Jp1fv1Xy0AHQaDkGA6mi11IpN2WYQiC42ZpQJ0
bF9dBYOd6lK/qYahMPIU3ft8nTou7uT4hyYhBeJRFOpSQowv8UNtiIBighmiWme+dRBrDEH50un
HSQQmip0gYTShjp0GoS4Bp0Bj+NFj7uwdVnIPvjlbGLTL96cv6fmew8zrHh/4YQKDHKVHtGd13t
S2utorR6xr5/xor4Ay++dFv5ykDv+eiohmDXSrh10Z8imhG7qUu3OV+2L85NeQq3q0s5lsk0kt+
6I08i5BZQaB6+WBQ==
X-Google-Smtp-Source: AGHT+IHZl2DnI8o+fjd17xb2dffaGOlfHzpmwfJ2QtfSIQcW5cpd6ZcIdZu5TG/j80oaT2nUjwA8yg==
X-Received: by 2002:a17:902:f546:b0:295:7423:4be2 with SMTP id
d9443c01a7336-2962ad06d1dmr52219535ad.3.1762351246458;
Wed, 05 Nov 2025 06:00:46 -0800 (PST)
Message-Id: <1762351216977.2511319142.2276851722@gmail.com>
To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>, cygwin AT cygwin DOT com
Subject: Re: Deadlock in cygwin1.dll when joining a thread before
thread_local initialization
Date: Wed, 05 Nov 2025 14:00:43 +0000
X-Mailer: Vivaldi Mail
User-Agent: Vivaldi Mail/7.6.3797.63
MIME-Version: 1.0
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: kikairoya via Cygwin <cygwin AT cygwin DOT com>
Reply-To: kikairoya <kikairoya AT gmail DOT com>
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

Thank you for the investigating.
I believe I understand what happens in the runtime.

I found that a similar problem has been reported to UCRT runtime, and the 
reporter says that Darwin libc and glibc does unlock the mutex while 
calling atexit-ed functions.

The report: 
https://developercommunity.visualstudio.com/t/atexit-deadlock-with-thread-safe-static-/1654756

glibc: 
https://sourceware.org/git/?p=glibc.git;a=blob;f=stdlib/cxa_finalize.c;hb=2642002380aafb71a1d3b569b6d7ebeab3284816#l96

Darwin: 
https://github.com/apple-open-source-mirror/Libc/blob/5e566be7a7047360adfb35ffc44c6a019a854bea/stdlib/FreeBSD/atexit.c#L274-L292


I'm also feel scared to do that, but it might be practically safe.

 > Thanks for the report. I looked into the issue and found the
 > cause is in newlib. I have confirmed that the following patch
 > fixes the issue, but I am not very sure unlocking mutex here
 > is safe. Let me consider a bit more.
 >
 >
 > diff --git a/newlib/libc/stdlib/__call_atexit.c 
b/newlib/libc/stdlib/__call_atexit.c
 > index 710440389..44f1f6acc 100644
 > --- a/newlib/libc/stdlib/__call_atexit.c
 > +++ b/newlib/libc/stdlib/__call_atexit.c
 > @@ -114,6 +114,11 @@ __call_exitprocs (int code, void *d)
 >
 >           ind = p->_ind;
 >
 > +#ifndef __SINGLE_THREAD__
 > +         /* Unlock __atexit_recursive_mutex; otherwise, the function 
fn() may
 > +            deadlock if it waits for another thread which calls 
atexit(). */
 > +         __lock_release_recursive(__atexit_recursive_mutex);
 > +#endif
 >           /* Call the function.  */
 >           if (!args || (args->_fntypes & i) == 0)
 >             fn ();
 > @@ -121,6 +126,9 @@ __call_exitprocs (int code, void *d)
 >             (*((void (*)(int, void *)) fn))(code, args->_fnargs[n]);
 >           else
 >             (*((void (*)(void *)) fn))(args->_fnargs[n]);
 > +#ifndef __SINGLE_THREAD__
 > +         __lock_acquire_recursive(__atexit_recursive_mutex);
 > +#endif
 >
 >           /* The function we called call atexit and registered another
 >              function (or functions).  Call these new functions before


--
Tomohiro Kashiwada (@kikairoya)

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019