Calling system() in multi-threads.

Takashi Yano takashi.yano@nifty.ne.jp
Wed Jul 16 14:52:36 GMT 2025


Hi Corinna,
On 2025年6月18日 20:31:27 +0900
Takashi Yano wrote:
> On 2025年6月17日 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?
-- 
Takashi Yano <takashi.yano@nifty.ne.jp>


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /