delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/09/29/10:43:49

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <002901c92241$9cfc7860$0200a8c0@whiterabc2znlh>
From: "Hirokazu Yamamoto" <ocean-city AT m2 DOT ccsnet DOT ne DOT jp>
To: <cygwin AT cygwin DOT com>
References: <003301c92110$336cee20$0200a8c0 AT whiterabc2znlh> <48DF3317 DOT 5060300 AT sh DOT cvut DOT cz> <20080928152527 DOT GA2219 AT ednor DOT casa DOT cgf DOT cx> <48DFA78A DOT 3020506 AT sh DOT cvut DOT cz> <20080928162701 DOT GB2219 AT ednor DOT casa DOT cgf DOT cx>
Subject: Re: crash if fork(2) from another thread
Date: Mon, 29 Sep 2008 23:42:32 +0900
MIME-Version: 1.0
X-Mailer: Microsoft Outlook Express 6.00.2800.1933
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

------=_NextPart_000_0026_01C9228D.0B0463E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

>Your test case worked fine for me with Cygwin 1.7.x.  I don't have a
>copy of 1.5.x handy to test.

> >> I don't see any reason why this shouldn't be allowed.  You should
> >> be able to do anything you want in a child process.
> >I do not think that is true. As per
> ><http://www.opengroup.org/onlinepubs/009695399/functions/fork.html>,
> >RATIONALE, the penultimate paragraph, it is basically undefined
behaviour.
>
> I wrote the current version of cygwin's fork.

I also confirmed previous code worked fine with Cygwin 1.7.
But attached code hangs on Cygwin 1.7. (Actually this is what
test_3_join_in_forked_from_thread is doing)

------=_NextPart_000_0026_01C9228D.0B0463E0
Content-Type: application/octet-stream;
	name="main.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="main.c"

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>

void *thread_func_2(void* args)
{
    puts("thread_func_2"); /* hang up here */
}

void *thread_func_1(void* args)
{
    int ret;
    pid_t pid;

    puts("thread_func_1");

    pid = fork();

    assert(pid != (pid_t)-1);

    if (pid != 0) /* parent process */
    {
        int status;

        printf("parent process (child pid = %d)\n", pid);

        waitpid(pid, &status, 0);

        puts("parent process end");
    }
    else /* child process */
    {
        pthread_t thread;

        puts("child process");

        ret = pthread_create(&thread, NULL, thread_func_2, NULL);
        assert(ret == 0);

        ret = pthread_join(thread, NULL);
        assert(ret == 0);

        puts("child process end");
    }

    return args;
}

int main()
{
    int ret;
    pthread_t thread;

    ret = pthread_create(&thread, NULL, thread_func_1, NULL);
    assert(ret == 0);

    ret = pthread_join(thread, NULL);
    assert(ret == 0);
}


------=_NextPart_000_0026_01C9228D.0B0463E0
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_0026_01C9228D.0B0463E0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019