www.digitalmars.com         C & C++   DMDScript  

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


          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


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;
    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 ) { 
        kill(parent_pid, SIGHUP); // send signal to parent
    if ( child_pid == -1 ) { 
    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

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