www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20256] New: problem with signal handling and parallel GC on

https://issues.dlang.org/show_bug.cgi?id=20256

          Issue ID: 20256
           Summary: problem with signal handling and parallel GC on linux
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: igor.khasilev gmail.com

Hello,

Attached code fails with dmd 2.087 and 2.088 if parallel GC scanning enabled.

import std.stdio;
import core.sys.posix.signal;
import core.thread;
import core.sys.posix.unistd;
import core.sys.posix.sys.wait;
import core.memory;
import std.algorithm;
import std.range;

void block(int signum) {
    sigset_t m;
    sigemptyset(&m);
    sigaddset(&m, signum);
    sigprocmask(SIG_BLOCK, &m, null);
}

void main()
{
    auto x = new int[](10000);
    iota(10000).each!(i => x ~= i); 
    GC.collect();  // ldc create thread here
    block(SIGHUP); // block works only for current thread, not for thread
created by GC.collect
    auto parent_pid = getpid();
    auto child_pid = fork();
    if ( child_pid == 0 ) { 
        //child
        kill(parent_pid, SIGHUP); // send signal to parent
        _exit(0);
    }   
    if ( child_pid == -1 ) { 
        _exit(0);
    }   
    Thread.sleep(1.seconds);
    writeln("This should be printed");
}

Expected output "This should be printed", instead program killed by signal
SIGHUP. This code works as expected if program started with
--DRT-gcopt=parallel:0

This is because there is no SIGHUP mask in sigmask of the GC stream (as if it
were cloned after calling sigprocmask from the main stream).

Problem would be fixed if scanner thread will have all signals blocked (except
signals it have to handle).

--
Sep 30 2019