D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15947 - [REG 2.069.0?] simple multithreaded program + "-profile=gc" = crash
Summary: [REG 2.069.0?] simple multithreaded program + "-profile=gc" = crash
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-21 15:45 UTC by Ivan Kazmenko
Modified: 2017-08-07 12:25 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ivan Kazmenko 2016-04-21 15:45:35 UTC
-----prfail1.d-----
import std.concurrency;
void someWork () {auto x = [1];}
void main () {spawn (&someWork);}
-----

The above program crashes with 2.071.0 down to 2.069.0 but still works on 2.068.2.  The command line is "dmd -g -profile=gc prfail1.d" on Windows (compiled to 32-bit by default).

The crash happens almost always, >90% of runs of the compiled program.  Here's the error output:

-----
object.Error@(0): Access Violation
----------------
0x00409651 in nothrow int rt.profilegc._staticDtor407().__foreachbody2(ref immutable(char)[], ref rt.profilegc.Entry)
0x00409986 in void rt.profilegc.__moddtor()
0x00427444 in __threadstartex
0x77869ED2 in RtlInitializeExceptionChain
0x77869EA5 in RtlInitializeExceptionChain
-----

With added "-m64", it just crashes and does not print anything.

This issue report originated as a forum post:
https://forum.dlang.org/post/vsjllasdndfrhhziiece@forum.dlang.org
Comment 1 Ivan Kazmenko 2016-04-21 15:46:07 UTC
Interestingly, a modified version does not crash:

-----prfail2.d-----
import std.concurrency;
void someWork () {auto x = [1];}
void main () {spawn (&someWork); someWork ();}
-----

I was curious if this guarantees that the spawned thread finishes before the main thread, but the third example, also crashing, seems to contradict that:

-----prfail3.d-----
import std.concurrency;
void someWork () {auto x = [1];}
void main () {
    spawnLinked (&someWork);
    try {receive ((int) {});}
    catch (LinkTerminated o) {}
}
-----
Comment 2 Vladimir Panteleev 2016-04-21 15:53:58 UTC
Issue 14511?
Comment 3 Ivan Kazmenko 2016-04-21 16:00:56 UTC
(In reply to Vladimir Panteleev from comment #2)
> Issue 14511?

The details are different, but perhaps the cause is the same.

I was hesitant to put this as a comment for 14511 because "-profile" and "-profile=gc" are of unknown relation to me, and 14511 seems to be about "-profile" initially.
Comment 4 Mihails Strasuns 2017-04-06 11:35:35 UTC
This sample is sufficient to reproduce the crash for me with -profile=gc :

---
void main ( )
{
    import core.thread;

    auto t = new Thread({
        auto x = new int;
    }).start();
}
```
Comment 5 github-bugzilla 2017-04-06 18:21:59 UTC
Commit pushed to stable at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/08835c01cf2d64a06c53739223edba55cc23db2f
Simple multithreaded program + "-profile=gc" = crash

Fixes issue 15947 (https://issues.dlang.org/show_bug.cgi?id=15947)
Fixes issue 14511 (https://issues.dlang.org/show_bug.cgi?id=14511)

Root problem was trying to increment non-existent AA field upon merging profile
stats. The code was also simplified to remove unnecessary condition.
Comment 6 github-bugzilla 2017-05-04 15:03:10 UTC
Commit pushed to master at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/08835c01cf2d64a06c53739223edba55cc23db2f
Simple multithreaded program + "-profile=gc" = crash
Comment 7 github-bugzilla 2017-08-07 12:25:50 UTC
Commit pushed to newCTFE at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/08835c01cf2d64a06c53739223edba55cc23db2f
Simple multithreaded program + "-profile=gc" = crash