[Gc] Cygwin and HANDLE_FORK/GC_handle_fork
Erik Bray <[email protected]> Wed, 29 Mar 2017 17:26:35 +0200
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <CAOTD34bN65HAWJdCLxOWCtJDwyvGFo4YoTkaFuRmsCibiH7B+A@mail.gmail.com> |
--001a1148407ec1c2ff054be033da Content-Type: text/plain; charset=UTF-8 Greetings, I recently encountered, by way of a bug report in Sage [1], a problem with using GC in a forked child process on Cygwin. The symptom is an unhandled SIGABRT issued from within GC_suspend during GC_stop_world in a child process forked from a process using GC. I've narrowed this down to a simple test program demonstrating the problem, attached. The output of a sample run (demonstrating the issue) looks like: parent pid: 17500 child pid: 2616 SuspendThread failed In this case, GC only knows about one thread, the one whose structure is in the first_thread variable. The problem is that post-fork, the member first_thread->handle no longer points to a valid HANDLE to any thread. So when GC_stop_world is hit and it tries to suspend all threads it knows about, SuspendThread fails and this abort is raised. This is with GC 7.2 configured with $ ./configure --enable-threads=posix This is easily gotten around with the pthread_atexit handlers that are installed if CAN_HANDLE_FORK is set and the global GC_handle_fork = 1. This appears to clean up the no longer valid thread struct, so there are no further errors. The problem, then, as I see it, is that GC can't work reliably on Cygwin (in a forking context) *without* HANDLE_FORK--that is, specifying --enable-handle-fork at configure time. So my proposal is to enable this feature by default on Cygwin. It works, and I see no reason *not* to have it. Thanks, Erik [1] https://trac.sagemath.org/ticket/22694 --001a1148407ec1c2ff054be033da Content-Type: text/x-csrc; charset=US-ASCII; name="gctest.c" Content-Disposition: attachment; filename="gctest.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_j0v47sdu0 I2luY2x1ZGUgPGdjLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN5cy93YWl0Lmg+ CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN5cy90aW1lLmg+CiNpbmNsdWRlIDxzdGRp by5oPgoKCmludCBtYWluKHZvaWQpIHsKICAgIHBpZF90IHBpZDsKICAgIHZvaWQgKmFkZHI7CiAg ICBpbnQgc2l6ZTsKICAgIHByaW50ZigicGFyZW50IHBpZDogJWRcbiIsIGdldHBpZCgpKTsKICAg IHNsZWVwKDUpOwoKICAgIGFkZHIgPSBHQ19tYWxsb2MoMSk7CiAgICBpZiAoKHBpZCA9IGZvcmso KSkgPT0gMCkgewogICAgICAgIC8qIENoaWxkICovCiAgICAgICAgc2xlZXAoNSk7CiAgICAgICAg d2hpbGUgKDEpIHsKICAgICAgICAgICAgLyogTWFrZSBhIGJ1bmNoIG9mIGxpdHRsZSBhbGxvY2F0 aW9ucyB1bnRpbCBHQ19jb2xsZWN0X29yX2V4cGFuZCBpcyBjYWxsZWQgKi8KICAgICAgICAgICAg c2l6ZSA9IHJhbmRvbSgpOwogICAgICAgICAgICBpZiAoc2l6ZSA8IDEwMDApIHsKICAgICAgICAg ICAgICAgIGFkZHIgPSBHQ19tYWxsb2NfYXRvbWljKHNpemUpOwogICAgICAgICAgICB9CiAgICAg ICAgfQogICAgfSBlbHNlIHsKICAgICAgICAvKiBQYXJlbnQgKi8KICAgICAgICBwcmludGYoImNo aWxkIHBpZDogJWRcbiIsIHBpZCk7CiAgICAgICAgd2FpdHBpZChwaWQsIE5VTEwsIDApOwogICAg ICAgIGV4aXQoMCk7CiAgICB9CiAgICByZXR1cm4gMDsKfQo= --001a1148407ec1c2ff054be033da Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ bdwgc mailing list [email protected] https://lists.opendylan.org/mailman/listinfo/bdwgc --001a1148407ec1c2ff054be033da--