DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 56ICHaNI2746808 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 56ICHaNI2746808 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=uYEuMGS0 X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09AF9385E443 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1752841055; bh=rlS9thjdrxTYVZu6dXCVGiDkU1VIPrS/L5QGUdIi7Qk=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uYEuMGS07Tj1Qx2wKiUIRc9UhmkrH9zc6adysPJ+TM9sEqb1s3cJhlDylO+5Bcd9s thK3xgyCoh1oetPsAusqRbMcX9T0WmzhdlPH+3cVa+cA+n4qkB2udeMUAsEqH2ru2w eX7HLnXXw0LCaspIguuZOZ1jZZ7CNIubunQRIJ8A= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F61C3858C60 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F61C3858C60 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752841022; cv=none; b=fOcc/VH+Wos50nWIW7RSjdOeS7G5V0yAroDcQOLV0xQAgglW8IhJpnhbJX8hL+TkTsWQNiogdrBtXYYnTyLiEsUSaHkQRjj0Ia1XRLdaMqka5AFwaH6irksUWRIBqw6nuQfjZPw4BKy/C+W+7Wnv1/nM1CI/qC4kTKptXY2AK0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752841022; c=relaxed/simple; bh=bSxnGno5mtGAqvoXLcE/GJzlX5+E14Yg8Gyww6C2LN0=; h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature; b=e0205vVoJRjQ+UGa22kigdOabofQomKNrWsAV+93OTbJDNy9Bt+0/EhUHAxMKv/pQeYUaYhQ/Et8qFkFEVanNb9+zwPPawFRtwxSKX3n7C8oL/KUAqom3f47uviUQxS/jkUsi3EyiX3Lrn+35CHVEHvdWXMS/YejnYDwZJDTdIc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F61C3858C60 Date: Fri, 18 Jul 2025 21:16:58 +0900 To: cygwin AT cygwin DOT com Subject: Re: Calling system() in multi-threads. Message-Id: <20250718211658.bea82938d46ff8bb8bacf90f@nifty.ne.jp> In-Reply-To: <20250718174247.5e3328ab5a9e25e42d3e4fcb@nifty.ne.jp> References: <20250617215411 DOT ebf69d1c18b55191a1b76c01 AT nifty DOT ne DOT jp> <20250618203127 DOT 71ac180de11230a9a6055185 AT nifty DOT ne DOT jp> <20250716235236 DOT 96055ec145d9a0528b50c357 AT nifty DOT ne DOT jp> <20250717231421 DOT 56b54f7e96266311101d4c08 AT nifty DOT ne DOT jp> <20250718004446 DOT 9ce9f7f208566ded1a676fd5 AT nifty DOT ne DOT jp> <20250718012800 DOT 45ae0a80ff8bcd286c176baa AT nifty DOT ne DOT jp> <20250718174247 DOT 5e3328ab5a9e25e42d3e4fcb AT nifty DOT ne DOT jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Takashi Yano via Cygwin Reply-To: Takashi Yano Content-Type: text/plain; charset="utf-8" Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 56ICHaNI2746808 On Fri, 18 Jul 2025 17:42:47 +0900 Takashi Yano wrote: > On Fri, 18 Jul 2025 09:54:20 +0200 > Corinna Vinschen wrote: > > On Jul 18 01:28, Takashi Yano via Cygwin wrote: > > > On Fri, 18 Jul 2025 00:44:46 +0900 > > > Takashi Yano wrote: > > > > On Thu, 17 Jul 2025 17:19:49 +0200 > > > > Corinna Vinschen wrote: > > > > > On Jul 17 23:14, Takashi Yano via Cygwin wrote: > > > > > > Hi Corinna, > > > > > > > > > > > > On Wed, 16 Jul 2025 17:36:42 +0200 > > > > > > Corinna Vinschen wrote: > > > > > > > On Jul 16 23:52, Takashi Yano via Cygwin wrote: > > > > > > > > Do you have any idea? > > > > > > > > > > > > > > Locking would be super-simple. > > > > > > > > > > > > > > But theoretically it should be possible to use a local child_info_spawn > > > > > > > variable at this point. The ch_spawn child_info_spawn instance is not > > > > > > > copied to the child anyway, so that should be safe. The same goes for > > > > > > > posix_spawn() then, btw. > > > > > > > > > > > > > > I checked the sources and I don't see any dependency to ch_spawn > > > > > > > from a spawning process, in contrast to an exec'ing process. That > > > > > > > doesn't mean there is none, just that I didn't find any. > > > > > > > > > > > > Thanks! > > > > > > As a starting point, I tried tntroducing locking. It almost works > > > > > > as expected, however, sometimes my STC in my first report is hangs > > > > > > if N is large e.g. 100. The patch is as attached. > > > > > > > > > > > > What am I missing? > > > > > > > > > > I don't know. You're perhaps not releasing the lock in all cases. > > > > > But I would have to debug this just like you ¯\_(ツ)_/¯ > > > > > > > > > > Out of curiosity, did you try using a locale child_info_spawn instance > > > > > instead? That would be a rather nice solution, but I'm pretty sure > > > > > there's some other problem lurking in the dark... > > > > > > > > I'm not sure what to do with local child_info_spawn. > > > > Some of other modules refer to ch_spawn, such as exception.cc and > > > > pinfo.cc. Also, has_execed* uses ch_spawn. What should we do for that? > > > > > > > > I've just tried simply the following patch, however, this also hangs > > > > with my STC. > > > > > > > > diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc > > > > index cb58b6eed..56fca6e45 100644 > > > > --- a/winsup/cygwin/spawn.cc > > > > +++ b/winsup/cygwin/spawn.cc > > > > @@ -944,6 +944,7 @@ spawnve (int mode, const char *path, const char *const *argv, > > > > int ret; > > > > > > > > syscall_printf ("spawnve (%s, %s, %p)", path, argv[0], envp); > > > > + child_info_spawn ch_spawn_local; > > > > > > > > if (!envp) > > > > envp = empty_env; > > > > @@ -951,7 +952,7 @@ spawnve (int mode, const char *path, const char *const *argv, > > > > switch (_P_MODE (mode)) > > > > { > > > > case _P_OVERLAY: > > > > - ch_spawn.worker (path, argv, envp, mode); > > > > + ch_spawn_local.worker (path, argv, envp, mode); > > > > /* Errno should be set by worker. */ > > > > ret = -1; > > > > break; > > > > @@ -961,7 +962,7 @@ spawnve (int mode, const char *path, const char *const *argv, > > > > case _P_WAIT: > > > > case _P_DETACH: > > > > case _P_SYSTEM: > > > > - ret = ch_spawn.worker (path, argv, envp, mode); > > > > + ret = ch_spawn_local.worker (path, argv, envp, mode); > > > > break; > > > > default: > > > > set_errno (EINVAL); > > > > > > The hang seems to be at acquiring the cygheap_protect lock in child sh.exe. > > > This lock is aquired only in _cfree() and _cmalloc(), so I am not sure why > > > cygheap_protect cannot be acquired at this point at all... > > > > How do the affected backtraces look like? > > > > Also, one reason could be that cygheap_protect is a SRWLOCK since > > 5d3e79ec6bb73 ("Cygwin: cygheap: use SRWLOCK for cygheap locking") > > > > SRWLOCK is not recursive. What if you revert this lock to a muto as > > before 5d3e79ec6bb73? > > Thanks! I'll try muto. Tried. If muto is used instead of SRWLock, hang does not happen anymore. However, sometimes "Bad address" happens. $ ./a.exe sh: line 1: /usr/bin/echo: Bad address sh: line 1: /usr/bin/echo: Bad address AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA 0 0 0 0 0 0 0 0 11 11 $ Heap might be broken? -- Takashi Yano -- 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