www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 114] New: Multithreaded applications crash upon garbage collection

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=114

           Summary: Multithreaded applications crash upon garbage collection
           Product: D
           Version: 0.154
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: patch
          Severity: critical
          Priority: P1
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: juanjo comellas.com.ar


There is a problem in std/thread.d in Phobos that appears when the garbage
collector runs and the gcx.mark() method is executed. Dave
<dave_member pathlink.com> provided a fix for this with the following message:

The problem is that the t.stackTop is not valid when it is passed into 
gcx.mark() because it is being munged as pauseAll returns (and lets the 
GC commence) before the stackTop is set for all of the paused threads.

    extern (C) static void pauseHandler(int sig)
    {
        int result;

        // Save all registers on the stack so they'll be scanned by the GC
        asm
        {
            pusha   ;
        }

        assert(sig == SIGUSR1);
        // Move sem_post to after t.stackTop = getESP();
        //sem_post(&flagSuspend);

        sigset_t sigmask;
        result = sigfillset(&sigmask);
        assert(result == 0);
        result = sigdelset(&sigmask, SIGUSR2);
        assert(result == 0);

        Thread t = getThis();
        t.stackTop = getESP();
        t.flags &= ~1;
        sem_post(&flagSuspend); // HERE
        while (1)
        {
            sigsuspend(&sigmask);   // suspend until SIGUSR2
            if (t.flags & 1)        // ensure it was resumeHandler()
            break;
        }

        // Restore all registers
        asm
        {
            popa    ;
        }
    }

I have already verified that this modification fixes the problem.


-- 
Apr 24 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=114


juanjo comellas.com.ar changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |juanjo comellas.com.ar





BTW, when the application crashes, the line reported by gdb is:


1318                byte *p = cast(byte *)(*p1);

The pointer that's being dereferenced by the GC is invalid. Here's a backtrace
of a test program that has two threads. The crash is happening on
thread 1.

  (gdb) thread apply all bt

Thread 2 (process 8953):





_D5mango2io6Socket6Socket4sendFAvE5mango2io6Socket6Socket5FlagsZi () at
/home/jcomellas/devel/d/mango_test/mango/io/Socket.d:1423

/home/jcomellas/devel/d/mango_test/mango/io/Socket.d:879

/home/jcomellas/devel/d/mango_test/mango/io/Conduit.d:198




std/thread.d:845



Thread 1 (process 8949):







_D5mango2io8selector12PollSelector12PollSelector11selectedSetFZC5mango2io8selector5model9ISelector13ISelectionSet
()
    at /home/jcomellas/devel/d/mango_test/mango/io/selector/PollSelector.d:353

_D8selector12testSelectorFC5mango2io8selector5model9ISelector9ISelectorZv () at
selector.d:142




-- 
Apr 24 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=114


juanjo comellas.com.ar changed:

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




-- 
May 04 2006