www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15491] New: std.parallelism conflicts with

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

          Issue ID: 15491
           Summary: std.parallelism conflicts with thread_detachInstance
           Product: D
           Version: D2
          Hardware: x86
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: jeremiep gmail.com

Hello, I get a crash during shutdown when having both a TaskPool and a
real-time thread detached through thread_detachInstance.

Here is the simplest program I could create to reproduce the bug:


module main;

import core.atomic;
import core.thread;
import core.sync.semaphore;

import std.parallelism;

shared bool running = true;

void threadMain() {
    while (running.atomicLoad) {
        Thread.sleep(dur!"msecs"(10));
    }
}

void main() {
    scope auto tasks = new TaskPool(4);
    scope (exit) tasks.finish(true);

    scope auto sync = new Semaphore(0);
    auto entry = {
        sync.notify();
        threadMain();
    };

    auto t = new Thread(entry).start();
    sync.wait();
    thread_detachInstance(t);

    running.atomicStore(false);
    t.join();
}


If you comment out the two lines creating and finishing the TaskPool, the
program runs correctly. Otherwise it exits with the following stack trace:

core.exception.RangeError src/core/thread.d(1186): Range violation
----------------
4   dmd_runYU3dOO                       0x000000010bf4a045 _d_arraybounds + 97
5   dmd_runYU3dOO                       0x000000010bf4b116 core.thread.__array
+ 38
6   dmd_runYU3dOO                       0x000000010bf4c108 pure nothrow  nogc
 safe int core.thread.Thread.getAll().__foreachbody1(ref core.thread.Thread) +
48
7   dmd_runYU3dOO                       0x000000010bf4c177 int
core.thread.Thread.opApply(scope int delegate(ref core.thread.Thread)) + 87
8   dmd_runYU3dOO                       0x000000010bf4c066 core.thread.Thread[]
core.thread.Thread.getAll() + 102
9   dmd_runYU3dOO                       0x000000010bf6c354 void
std.parallelism._sharedStaticDtor1358() + 24
10  dmd_runYU3dOO                       0x000000010bf6c218 void
std.parallelism.__modshareddtor() + 8
11  dmd_runYU3dOO                       0x000000010bf5eaa6 void
rt.minfo.__T17runModuleFuncsRevS442rt5minfo11ModuleGroup8runDtorsMFZ9__lambda1Z.runModuleFuncsRev(const(immutable(object.ModuleInfo)*)[])
+ 86
12  dmd_runYU3dOO                       0x000000010bf5e500 void
rt.minfo.ModuleGroup.runDtors() + 16
13  dmd_runYU3dOO                       0x000000010bf5e85b int
rt.minfo.rt_moduleDtor().__foreachbody1(ref rt.sections_osx.SectionGroup) + 27
14  dmd_runYU3dOO                       0x000000010bf5e83b rt_moduleDtor + 19
15  dmd_runYU3dOO                       0x000000010bf5a933 rt_term + 107
16  dmd_runYU3dOO                       0x000000010bf5ad51 void
rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
+ 61
17  dmd_runYU3dOO                       0x000000010bf5acd3 void
rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) + 55
18  dmd_runYU3dOO                       0x000000010bf5ac25 _d_run_main + 497
19  dmd_runYU3dOO                       0x000000010bf3dd57 main + 15
20  libdyld.dylib                       0x00007fff9a4d25c8 start + 0
21  ???                                 0x0000000000000000 0x0 + 0

--
Dec 31 2015