Bug 11492 – Executable with thread termination crashes (worked in 2.63, works on Windows)
Status
RESOLVED
Resolution
DUPLICATE
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-11-10T13:02:00Z
Last change time
2013-11-14T04:28:29Z
Assigned to
nobody
Creator
atila.neves
Comments
Comment #0 by atila.neves — 2013-11-10T13:02:07Z
This is on dmd 2.64.2 on Arch Linux 64-bit. Works on Windows, used to work in 2.63. Code to reproduce:
import std.concurrency;
private void threadWriter() {
for(bool running = true; running;) {
receive(
(Tid i) {
},
(OwnerTerminated trm) {
running = false;
}
);
}
}
void main() {
spawn(&threadWriter);
}
dmd thead.d
./thread.d
zsh: segmentation fault (core dumped) ./thread
Comment #1 by mk — 2013-11-10T14:53:30Z
This has been fixed recently (see bug 11309 and bug 11378). Are you sure you are running the latest version ? If so, mark as regression.
Comment #2 by atila.neves — 2013-11-11T01:41:24Z
(In reply to comment #1)
> This has been fixed recently (see bug 11309 and bug 11378). Are you sure you
> are running the latest version ? If so, mark as regression.
There are no newer packages for Arch. To make sure, I downloaded the zip with dmd 2.064.2 from dlang.org just now, used it to compile the sample program for this bug and the resulting binary crashed.
Comment #3 by mk — 2013-11-11T04:29:48Z
It seems to crash in dpaste too.
*** This issue has been marked as a duplicate of issue 11309 ***
Comment #4 by mk — 2013-11-11T05:39:59Z
Actually this bug may no be a dup of 11309, as that bug did not segfault, I confused it with another ralated issue, but I'm sure Martin Nowak will sort it out ;-)
Comment #5 by atila.neves — 2013-11-12T03:16:52Z
This example from TDPL (the only difference is the std.exception import for enforce) also results in a binary that crashes when compiling with dmd 2.064.2:
import std.concurrency, std.stdio, std.exception;
void main() {
auto low = 0, high = 100;
auto tid = spawn(&fun, low, high);
foreach(i; low .. high) {
writeln("Main thread: ", i);
tid.send(thisTid, i);
enforce(receiveOnly!Tid() == tid);
}
}
void fun(int low, int high) {
for(;;) {
auto msg = receiveOnly!(Tid, int)();
writeln("Secondary thread: ", msg[1]);
msg[0].send(thisTid);
}
}
Comment #6 by code — 2013-11-12T15:15:10Z
Both examples work correctly for me.
In the latter there is an unhandled exception. std.concurrency.OwnerTerminated@std/concurrency.d(234): Owner terminated
I tried 2.064.2 and master with all 32/64 compiler combinations.
It seems like threads don't work on dpaste.
http://dpaste.dzfl.pl/d6f2fedb (tried dmd 2.064.2, dmd git, ldc 0.12.0).
Comment #7 by code — 2013-11-12T15:16:55Z
Can you find out the function where the segfault happens?
Comment #8 by atila.neves — 2013-11-13T05:32:57Z
(In reply to comment #6)
> Both examples work correctly for me.
> In the latter there is an unhandled exception.
> std.concurrency.OwnerTerminated@std/concurrency.d(234): Owner terminated
I get that unhandled exception in 2.063. On 2.064 it crashes.
Comment #9 by atila.neves — 2013-11-13T05:34:13Z
(In reply to comment #7)
> Can you find out the function where the segfault happens?
In the last example (the one from TDPL) I don't get a segfault, I get SIGILL:
#0 0x00000000004a44f0 in ?? ()
#1 0x00007ffff7ecef08 in ?? ()
#2 0x00007ffff7de668d in _dl_lookup_symbol_x () from /lib64/ld-linux-x86-64.so.2
#3 0x00000000004695eb in std.variant.__T8VariantNVm32Z.VariantN.__T10convertsToTS3std8typecons35__T5TupleTS3std11concurrency3TidTiZ5TupleZ.convertsTo() (
this=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T10convertsToTS3std8typecons35__T5TupleTS3std11concurrency3TidTiZ5TupleZ.convertsTo()".>)
at /usr/include/dlang/dmd/std/variant.d:633
#4 0x000000000046957e in std.concurrency.Message.__T10convertsToTS3std11concurrency3TidTiZ.convertsTo() (
this=<error reading variable: Could not find the frame base for "std.concurrency.Message.__T10convertsToTS3std11concurrency3TidTiZ.convertsTo()".>) at /usr/include/dlang/dmd/std/concurrency.d:125
#5 0x0000000000468fb6 in std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>,
msg=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>) at /usr/include/dlang/dmd/std/concurrency.d:1150
#6 0x00000000004693a6 in std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>,
list=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>) at /usr/include/dlang/dmd/std/concurrency.d:1238
#7 0x0000000000468ef9 in std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>,
_param_3=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>,
_param_2=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>,
_param_1=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>,
_param_0=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTDFNbNfS3std11concurrency3TidiZvTPFNaNfC3std11concurrency14LinkTerminatedZvTPFNaNfC3std11concurrency15OwnerTerminatedZvTPFS3std7variant17__T8VariantNVm32Z8VariantNZvZ.get()".>) at /usr/include/dlang/dmd/std/concurrency.d:1314
#8 0x0000000000468c41 in std.concurrency.__T11receiveOnlyTS3std11concurrency3TidTiZ.receiveOnly() (
__HID10=<error reading variable: Could not find the frame base for "std.concurrency.__T11receiveOnlyTS3std11concurrency3TidTiZ.receiveOnly()".>) at /usr/include/dlang/dmd/std/concurrency.d:718
#9 0x000000000045e9c8 in concurrency_tdpl.fun() (high=<error reading variable: Could not find the frame base for "concurrency_tdpl.fun()".>,
low=<error reading variable: Could not find the frame base for "concurrency_tdpl.fun()".>) at concurrency_tdpl.d:15
#10 0x000000000045ebc9 in std.concurrency.__T6_spawnTPFiiZvTiTiZ._spawn() (this=<error reading variable: Could not find the frame base for "std.concurrency.__T6_spawnTPFiiZvTiTiZ._spawn()".>)
at /usr/include/dlang/dmd/std/concurrency.d:487
#11 0x0000000000485996 in core.thread.Thread.run() ()
#12 0x000000000048571d in thread_entryPoint ()
#13 0x00007ffff7bc70a2 in start_thread () from /usr/lib/libpthread.so.0
#14 0x00007ffff73ee49d in clone () from /usr/lib/libc.so.6
Comment #10 by atila.neves — 2013-11-13T05:35:51Z
(In reply to comment #7)
> Can you find out the function where the segfault happens?
In the original example:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7308700 (LWP 5006)]
0x0000000000471b83 in std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler() (
parm=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler()".>,
pStore=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler()".>,
selector=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler()".>)
at /usr/include/dlang/dmd/std/variant.d:294
294 switch (selector)
(gdb) bt
#0 0x0000000000471b83 in std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler() (
parm=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler()".>,
pStore=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler()".>,
selector=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T7handlerTC3std11concurrency15OwnerTerminatedZ.handler()".>)
at /usr/include/dlang/dmd/std/variant.d:294
#1 0x000000000046f5eb in std.variant.__T8VariantNVm32Z.VariantN.__T10convertsToTS3std11concurrency3TidZ.convertsTo() (
this=<error reading variable: Could not find the frame base for "std.variant.__T8VariantNVm32Z.VariantN.__T10convertsToTS3std11concurrency3TidZ.convertsTo()".>) at /usr/include/dlang/dmd/std/variant.d:633
#2 0x000000000046f57e in std.concurrency.Message.__T10convertsToTS3std11concurrency3TidZ.convertsTo() (
this=<error reading variable: Could not find the frame base for "std.concurrency.Message.__T10convertsToTS3std11concurrency3TidZ.convertsTo()".>) at /usr/include/dlang/dmd/std/concurrency.d:123
#3 0x000000000046f005 in std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>,
msg=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>)
at /usr/include/dlang/dmd/std/concurrency.d:1150
#4 0x000000000046f277 in std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>,
msg=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>)
at /usr/include/dlang/dmd/std/concurrency.d:1189
#5 0x000000000046f2ba in std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>,
msg=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>)
at /usr/include/dlang/dmd/std/concurrency.d:1201
#6 0x000000000046f32c in std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>,
list=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>)
at /usr/include/dlang/dmd/std/concurrency.d:1217
#7 0x000000000046ef51 in std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get() (
this=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>,
_param_1=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>,
_param_0=<error reading variable: Could not find the frame base for "std.concurrency.MessageBox.__T3getTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.get()".>)
at /usr/include/dlang/dmd/std/concurrency.d:1314
#8 0x000000000046ed9a in std.concurrency.__T7receiveTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.receive() (
_param_1=<error reading variable: Could not find the frame base for "std.concurrency.__T7receiveTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.receive()".>,
_param_0=<error reading variable: Could not find the frame base for "std.concurrency.__T7receiveTPFNaNbNfS3std11concurrency3TidZvTDFNbNfC3std11concurrency15OwnerTerminatedZvZ.receive()".>)
at /usr/include/dlang/dmd/std/concurrency.d:635
#9 0x000000000046ba78 in thread_local_singleton.threadWriter() () at thread_local_singleton.d:8
#10 0x0000000000472863 in std.concurrency.__T6_spawnTPFZvZ._spawn() (this=<error reading variable: Could not find the frame base for "std.concurrency.__T6_spawnTPFZvZ._spawn()".>)
at /usr/include/dlang/dmd/std/concurrency.d:487
#11 0x0000000000495466 in core.thread.Thread.run() ()
#12 0x00000000004951ed in thread_entryPoint ()
#13 0x00007ffff7bc70a2 in start_thread () from /usr/lib/libpthread.so.0
#14 0x00007ffff73ee49d in clone () from /usr/lib/libc.so.6
Comment #11 by code — 2013-11-13T13:49:19Z
Apparently it crashes in the Variant code when it tests for conversion.
Can you try the following small program with your setup?
cat > bug.d << CODE
import std.concurrency, std.variant, std.stdio;
void main()
{
Variant v;
v = new OwnerTerminated(thisTid);
if (v.convertsTo!Tid())
writeln("does convert");
else
writeln("doesn't convert");
}
CODE
Comment #12 by atila.neves — 2013-11-13T14:55:32Z
(In reply to comment #11)
> Apparently it crashes in the Variant code when it tests for conversion.
> Can you try the following small program with your setup?
>
> cat > bug.d << CODE
> import std.concurrency, std.variant, std.stdio;
>
> void main()
> {
> Variant v;
> v = new OwnerTerminated(thisTid);
> if (v.convertsTo!Tid())
> writeln("does convert");
> else
> writeln("doesn't convert");
> }
> CODE
It crashes on the convertsTo line. I copied std.variant into my own copy and inserted writelns since I couldn't get gdb to tell me where it crashed.
convertsTo seems to have all its local variables in order then promptly crashes when it calls fptr in line 633. It makes it through to handler!(A) up to line 294 then crashes on the switch. Again, no help from the debugger. I printed the value of selector just before the switch statement and it contains, as expected, OpID.testConversion. I also added a writeln after every case, including default, and none of them are printed. I tried single-stepping but it just seems to crash on the switch.
Comment #13 by code — 2013-11-13T16:07:28Z
Looks much like a duplicate of bug 11406.
Can you check whether ld.bfd works for you?
Comment #14 by atila.neves — 2013-11-14T04:27:47Z
(In reply to comment #13)
> Looks much like a duplicate of bug 11406.
> Can you check whether ld.bfd works for you?
Sigh... I actually considered this once while at work then forgot about it. ld.bfd works.
I agree this is a duplicate, it's just that it manifests in a lot worse way with std.concurrency.
Comment #15 by atila.neves — 2013-11-14T04:28:29Z
*** This issue has been marked as a duplicate of issue 11406 ***