www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compiling with -profile=gc makes program crash - why?

reply Ivan Kazmenko <gassa mail.ru> writes:
I'm trying to use DMD option "-profile=gc".  With this option, 
the following simple 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).

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

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.

Am I doing something wrong, or is it a 2.069 regression?

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) {}
}
-----

Ivan Kazmenko.
Apr 20 2016
parent reply Ivan Kazmenko <gassa mail.ru> writes:
On Wednesday, 20 April 2016 at 22:27:36 UTC, Ivan Kazmenko wrote:
 I'm trying to use DMD option "-profile=gc".  With this option, 
 the following simple 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).
Ouch, meant to post to D.learn. Sorry! Well, perhaps no point in reposting now.
Apr 20 2016
parent reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Wednesday, 20 April 2016 at 22:31:31 UTC, Ivan Kazmenko wrote:
 On Wednesday, 20 April 2016 at 22:27:36 UTC, Ivan Kazmenko 
 wrote:
 I'm trying to use DMD option "-profile=gc".  With this option, 
 the following simple 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).
Ouch, meant to post to D.learn. Sorry! Well, perhaps no point in reposting now.
You are using "spawn". So it is a multithreaded program. -profile=gc doesn't work with multithreadd programs. Always creates problems.
Apr 21 2016
next sibling parent reply Ivan Kazmenko <gassa mail.ru> writes:
On Thursday, 21 April 2016 at 09:23:26 UTC, tcak wrote:

 I'm trying to use DMD option "-profile=gc".
 You are using "spawn". So it is a multithreaded program. 
 -profile=gc doesn't work with multithreadd programs. Always 
 creates problems.
Humm, when I searched whether it should work, I only found a reassuring post by Walter[1] almost a year ago. The issue tracker does not seem to contain an entry either. Perhaps I should create one, then. [1] http://forum.dlang.org/post/mia2kf$djb$1 digitalmars.com
Apr 21 2016
parent reply Ivan Kazmenko <gassa mail.ru> writes:
On Thursday, 21 April 2016 at 10:57:12 UTC, Ivan Kazmenko wrote:
 Humm, when I searched whether it should work, I only found a 
 reassuring post by Walter[1] almost a year ago.  The issue 
 tracker does not seem to contain an entry either.  Perhaps I 
 should create one, then.

 [1] http://forum.dlang.org/post/mia2kf$djb$1 digitalmars.com
Issue created: https://issues.dlang.org/show_bug.cgi?id=15947
Apr 21 2016
parent Walter Bright <newshound2 digitalmars.com> writes:
On 4/21/2016 8:47 AM, Ivan Kazmenko wrote:
 Issue created:
 https://issues.dlang.org/show_bug.cgi?id=15947
Thank you.
Apr 21 2016
prev sibling parent jmh530 <john.michael.hall gmail.com> writes:
On Thursday, 21 April 2016 at 09:23:26 UTC, tcak wrote:
 You are using "spawn". So it is a multithreaded program. 
 -profile=gc doesn't work with multithreadd programs. Always 
 creates problems.
Then it would probably help if that is mentioned on this page somewhere. https://dlang.org/dmd-windows.html
Apr 21 2016