[Issue 13330] New: Calling std.c.stdlib.exit() from child threads causes segfault

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Aug 18 15:54:42 PDT 2014


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

          Issue ID: 13330
           Summary: Calling std.c.stdlib.exit() from child threads causes
                    segfault
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: andrei at erdani.com

Repro program:

import std.stdio, std.concurrency;

static void thread_run() {
  int[int] testMap;
  // should throw an out of range exception
  writeln("child: running ...");
  try {
    int testValue = testMap[10];
  } catch(Throwable e) {
    writefln("Exception in child thread: %s", e);
    std.c.stdlib.exit(0);
  }
  writeln("child: testValue set, sent back to parent");
  ownerTid.send(1);
}

int main() {
  writeln("partent: starting child thread ...");
  Tid child = spawn(&thread_run);
  int stop = 0;
  while(stop <= 0) {
    stop = receiveOnly!int();
    writefln("parent: received from child: %s, exiting...", stop);
  }
  writeln("exiting");
  return 0;
} 


OUTPUT: 
[ghwang at dev1817 ~/test] ./testException
partent: starting child thread ...
child: running ...
Exception in child thread: core.exception.RangeError at testException(8): Range
violation
----------------
./testException(_d_array_bounds+0x26) [0x48f3a6]
./testException() [0x46d17e]
./testException(void testException.thread_run()+0x6a) [0x46214e]
./testException(_D3std11concurrency16__T6_spawnTPFZvZ6_spawnFbPFZvZS3std11concurrency3Tid4execMFZv+0x3d)
[0x465761]
./testException(void core.thread.Thread.run()+0x2a) [0x49a306]
./testException(thread_entryPoint+0x165) [0x49a08d]
/usr/local/fbcode/gcc-4.8.1-glibc-2.17-fb/lib/libpthread.so.0(+0x7fa8)
[0x7fa5256adfa8]
/usr/local/fbcode/gcc-4.8.1-glibc-2.17-fb/lib/libc.so.6(clone+0x6d)
[0x7fa524ec35ad]
Segmentation fault

--


More information about the Digitalmars-d-bugs mailing list