DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 56GFb6VO3194039 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 56GFb6VO3194039 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=DnvRpNKl X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 162F93857711 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1752680226; bh=W3S/IJHnWVqMuq5pFyQz4l4lIFuG1PS+zhPFCuSWF9I=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DnvRpNKlQYRTF2RRW8YGD4QU+pzngcLFUjFil/6aVcMauOMXsn7EOywXyaS63JoUc NpqyWzdaDxbdAd7hbwz4yFivxaFxf6svJCwupR+52fNBm7W+41HCEtvIYRXS5AlhuB pTPZlD7tHXP2A74XxtZjZ2SqYf2OJlRdb/nT5Djo= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13B853857BB6 Date: Wed, 16 Jul 2025 17:36:42 +0200 To: cygwin AT cygwin DOT com Subject: Re: Calling system() in multi-threads. Message-ID: Mail-Followup-To: cygwin AT cygwin DOT com 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250716235236.96055ec145d9a0528b50c357@nifty.ne.jp> 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: Corinna Vinschen via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Corinna Vinschen Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Jul 16 23:52, Takashi Yano via Cygwin wrote: > Hi Corinna, > > On Wed, 18 Jun 2025 20:31:27 +0900 > Takashi Yano wrote: > > 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. > > 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. Corinna -- 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