Thread overview
[Issue 2405] New: std.gc.fullCollect hangs with multiple threads.
Oct 09, 2008
d-bugmail
Oct 21, 2008
d-bugmail
Oct 21, 2008
d-bugmail
October 09, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2405

           Summary: std.gc.fullCollect hangs with multiple threads.
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: ludwig@informatik.uni-luebeck.de


A bit difficult to debug using the existing debuggers - but when another background thread is active in addition to the main thread, the main thread seems to pause or deadlock itself when fullCollect is called (implicitly or explicitly). This makes threaded programming almost impossible atm and is a complete blocker for me.

This is a regression from 2.018. Not tested on Linux.

The following test code reproduces the problem 100% of the time on my dual-core system:
---
import std.gc;
import std.stdio;
import std.thread;
import std.c.windows.windows;

int main()
{
        (new Thread(delegate int(){
                Sleep(500); // simulate some work
                return 0;
        })).start();

        writeln("Running fullCollect..");
        std.gc.fullCollect();
        writeln(".. done");

        assert(false, "Did not hang!");

        return 0;
}
---


The stack trace for the main thread looks like this during the hang:
---
#0 ?? () from ntdll.dll
#1 0x004bf44e in void std.thread.Thread.pause(void*) () from thread
#2 0x005295c2 in uint gcx.Gcx.fullcollect(void*, void*) () from gcx
#3 0x0051b140 in void gcx.GC.fullCollect(void*) () from gcx
#4 0x004bf013 in void std.gc.fullCollect() () from gc
#5 0x004bef4c in _main () from dmain2
#6 0x0053a211 in _mainCRTStartup () from constart
#7 0x7d4e992a in ?? () from KERNEL32.dll
---

Sidenote:
There seems to be another issue with concurrent allocations/frees which has
proven itself to be hard to reproduce in a testcase (might be
http://d.puremagic.com/issues/show_bug.cgi?id=1957).


-- 

October 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2405





------- Comment #1 from ludwig@informatik.uni-luebeck.de  2008-10-21 02:03 -------
*** Bug 2404 has been marked as a duplicate of this bug. ***


-- 

October 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2405


ludwig@informatik.uni-luebeck.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from ludwig@informatik.uni-luebeck.de  2008-10-21 02:05 -------
Fixed with the switch to druntime.


--