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.

..mark


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

Reply via email to