DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 55IBWAQI1009684
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 55IBWAQI1009684
X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5F883852760
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E5F883852760
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750246291; cv=none;
 b=T1chwjyvFdsF0ULkJsuFMiys7rzujqk49zX9gsp36WzBoOiL+OxCRgaHTgVSeVlD26uwnksE8nxYnIaSgIr+/mDq8T9bIF8Sq8aO0dn24iT+Ki1dkdz+K3hAYcrGOpDRRLn+Q3iks7dCT7W+H0rXqLnwEEOVDPXWq9+A6zDjaK0=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1750246291; c=relaxed/simple;
 bh=R/6Nad2Fhk7q8zRi2oVl0rR1Rnrl1+pKZvva9/ecXdg=;
 h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature;
 b=tCO/j+iFSclb9AAKQuH2QWiZg9/z5h8gFmO+lF6t049bSXWXdfb4wM9x37ED/87IuydX2yaWFC6PIvqS7/9IgHyD7G/4i7edMmzuTkYSoK60PisBh6QwhAy9+Py+GuGrOyvGEJVvEMLTnT8GGELIUIpIckthWerUfQKlroAflO0=
ARC-Authentication-Results: i=1; server2.sourceware.org
Date: Wed, 18 Jun 2025 20:31:27 +0900
To: cygwin@cygwin.com
Subject: Re: Calling system() in multi-threads.
Message-Id: <20250618203127.71ac180de11230a9a6055185@nifty.ne.jp>
In-Reply-To: <eb7786ee-dc7a-4689-9d17-b842e581d7c7@maxrnd.com>
References: <20250617215411.ebf69d1c18b55191a1b76c01@nifty.ne.jp>
 <eb7786ee-dc7a-4689-9d17-b842e581d7c7@maxrnd.com>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Takashi Yano via Cygwin <cygwin@cygwin.com>
Reply-To: Takashi Yano <takashi.yano@nifty.ne.jp>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

On Tue, 17 Jun 2025 15:42:26 -0700
Mark Geisert wrote:
> Hi Takashi,
> 
> On 6/17/2025 5:54 AM, Takashi Yano via Cygwin wrote:
> > Hi,
> > 
> > If system() is called in parallel in threads, system()
> > fails with exit code 127.
> > 
> > Just compile pthread_system.c attached and run.
> > 
> > I believe system() is multi-thread safe so the STC
> > should work.
> 
> I regret to inform that system() is not currently MT-safe.  I discovered 
> this a few years ago when porting YAFU (Yet Another Factoring Utility).
> 
> I ended up supplying a wrapper that serialized the system() call itself 
> but allowed multiple wrappers (and thus child processes) to be running 
> at the same time.  I never got around to supplying a fix for Cygwin. 
> I've attached the code.
> HTH somehow,

Thanks for the information. I guess the cause is that accessing
child_info_spawn NO_COPY ch_spawn;
in spwan.cc conflicts with other threads. I wonder ch_spawn should
be thread-specific. Or should be guarded by lock.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

-- 
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
