public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: proc_waiter: error on read of child wait pipe 0x0, Win32 error 6
Date: Fri, 14 Jan 2022 09:22:27 +0900	[thread overview]
Message-ID: <20220114092227.0beae61df0394925212fd6c4@nifty.ne.jp> (raw)
In-Reply-To: <12affe5c-6f2c-ee89-7e21-ac1b91c3d58e@maxrnd.com>

On Thu, 13 Jan 2022 16:11:04 -0800
Mark Geisert wrote:
> Takashi Yano wrote:
> > On Wed, 12 Jan 2022 07:41:41 +0100
> > Marco Atzeri wrote:
> >> On 12.01.2022 07:27, Jay K wrote:
> >>> Ok, here is a small demonstration of the problem.
> >>>
> >>> #include <stdlib.h>
> >>> #include <stdio.h>
> >>> #include <windows.h>
> >>>
> >>> unsigned __stdcall thread(void* p)
> >>> {
> >>>     unsigned i;
> >>>     for (i = 0; i < 100; ++i)
> >>>      system("./a.exe");
> >>>     return 0;
> >>> }
> >>>
> >>> int main()
> >>> {
> >>> unsigned i;
> >>> HANDLE threads[100] = {0};
> >>> FILE* f = fopen("a.c", "w");
> >>> fprintf(f, "int main() { return 0; }\n");
> >>> fclose(f);
> >>
> >>
> >> so you are mixing Cygwin and Windows calls ?
> >> That is looking for trouble.
> >>
> >> Or it is a tentative to produce a test case ?
> > 
> > I found that the same happens even with pthread rather than
> > win32 thread functions.
> > 
> > #include <stdlib.h>
> > #include <pthread.h>
> > 
> > void *thread(void *p)
> > {
> > 	system("true");
> > 	return NULL;
> > }
> > 
> > int main()
> > {
> > 	int i;
> > 	pthread_t threads[2];
> > 
> > 	for (i = 0; i < 2; i++)
> > 		pthread_create(&threads[i], NULL, thread, NULL);
> > 
> > 	for (i = 0; i < 2; i++)
> > 		pthread_join(threads[i], NULL);
> > 
> > 	return 0;
> > }
> > 
> > Executing above code results in hang with message:
> >        0 [waitproc] a 786 proc_waiter: error on read of child wait pipe 0x0, Win32 error 6
> > 
> 
> POSIX does not require system() to be thread-safe.  On Cygwin, it isn't.  When I 
> ran into this a while back, I implemented an application wrapper around system() 
> to serialize calls.  It's tricky because you want to serialize just the mechanism 
> of system(), not the programs that the multiple system()s call.

Ah, indeed.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/system.html
says:
  "The system() function need not be thread-safe."
while Linux's system() is MT-safe.

Thanks.

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

  reply	other threads:[~2022-01-14  0:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12  4:12 Jay K
2022-01-12  5:57 ` Jay K
2022-01-12  6:27   ` Jay K
2022-01-12  6:41     ` Marco Atzeri
2022-01-13 23:52       ` Takashi Yano
2022-01-14  0:11         ` Mark Geisert
2022-01-14  0:22           ` Takashi Yano [this message]
2022-01-13  6:40     ` Jay K
2022-01-13 13:42       ` Eliot Moss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220114092227.0beae61df0394925212fd6c4@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).