www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What wrong?

reply "Fyodor Ustinov" <ufm ufm.su> writes:
Simple code:

http://pastebin.com/raw.php?i=7jVeMFXQ

This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based 
on DMD v2.066.1 and LLVM 3.5.0.

$ ./z
TUQLUE
42
11

Compiled by DMD v2.067.1 the program crashes:
$ ./aa
TUQLUE
Segmentation fault

What I'm doing wrong?
May 01 2015
next sibling parent reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote:
 Simple code:

 http://pastebin.com/raw.php?i=7jVeMFXQ

 This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) 
 based on DMD v2.066.1 and LLVM 3.5.0.

 $ ./z
 TUQLUE
 42
 11

 Compiled by DMD v2.067.1 the program crashes:
 $ ./aa
 TUQLUE
 Segmentation fault

 What I'm doing wrong?
I think the problem is in these lines: ----- receive( (supervisorAnswer a) => r = a.ret ); Partially it works :) ----- import std.variant; private struct Exit{}; private struct supervisorAnswer { Variant ret; } private __gshared Tid supervisorTid; private void supervisor() { static Variant[string] zval; bool done = false; void _store(T)(string k, T v) { assert(k.length > 0); zval[k] = v; } void _get(Tid id, string k) { id.send(supervisorAnswer(zval.get(k, Variant("NOTFOUND")))); } while (!done) { supervisorAnswer answer; receive( (Exit s) { done = true; }, &_store!long, &_store!ulong, &_store!int, &_store!uint, &_store!float, &_store!double, &_store!string, &_store!Variant, &_get, (Variant e) { writeln(e); }, ); } } Variant Get(const string s) { Variant r; supervisorTid.send(thisTid, s); writeln("TUQLUE"); /*receive( (supervisorAnswer a) => r = a.ret );*/ writeln("42"); return r; } void Set(T)(const string s, T v) { supervisorTid.send(s, v); } shared static this() { supervisorTid = spawn(&supervisor); } shared static ~this() { send(supervisorTid, Exit()); } void main() { Set("1", 11); writeln(Get("1")); send(supervisorTid, Exit()); thread_joinAll(); }
May 02 2015
parent reply "Fyodor Ustinov" <ufm ufm.su> writes:
On Saturday, 2 May 2015 at 19:13:45 UTC, Dennis Ritchie wrote:
 On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote:
 Simple code:

 http://pastebin.com/raw.php?i=7jVeMFXQ

 This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) 
 based on DMD v2.066.1 and LLVM 3.5.0.

 $ ./z
 TUQLUE
 42
 11

 Compiled by DMD v2.067.1 the program crashes:
 $ ./aa
 TUQLUE
 Segmentation fault

 What I'm doing wrong?
I think the problem is in these lines: ----- receive( (supervisorAnswer a) => r = a.ret ); Partially it works :)
I see it by the lack of "42". :) But why is this "receive" breaks down?
May 02 2015
parent reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote:
 I see it by the lack of "42". :)

 But why is this "receive" breaks down?
Report, please, about it (D)evepopers :) https://issues.dlang.org/
May 02 2015
parent reply "Fyodor Ustinov" <ufm ufm.su> writes:
On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote:
 On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote:
 I see it by the lack of "42". :)

 But why is this "receive" breaks down?
Report, please, about it (D)evepopers :) https://issues.dlang.org/
I'm not sure that it's not my fault. So I hope that will come by knowledgeable people and say "Hey, buddy, your mistake is..." :)
May 03 2015
next sibling parent "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote:
 I'm not sure that it's not my fault. So I hope that will come 
 by knowledgeable people and say "Hey, buddy, your mistake 
 is..." :)
OK. But if one does not come within three days :), duplicate topic in this section: http://forum.dlang.org/group/digitalmars.D
May 03 2015
prev sibling parent reply "sclytrack" <sclytrack fake.com> writes:
On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote:
 On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote:
 On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote:
 I see it by the lack of "42". :)

 But why is this "receive" breaks down?
import std.stdio; import std.concurrency; struct Answer { int number = 10; ~this() { writeln(number); } } void threadRoutine() { receive( (int value){ } //handle question ); ownerTid.send( Answer() ); //answer } void main() { Tid childId = spawn(&threadRoutine); childId.send(100); //question receive((Answer t) {}); //answer } //DMD64 D Compiler v2.067.1 /* 10 10 10 10 10 10 10 10 10 10 10 7080544 10 10 10 */
May 05 2015
parent "sclytrack" <sclytrack fake.com> writes:
On Tuesday, 5 May 2015 at 07:41:04 UTC, sclytrack wrote:
 On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote:
 On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote:
 On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote:
 I see it by the lack of "42". :)

 But why is this "receive" breaks down?
import std.stdio; import std.variant; struct SoMany { int number = 10; ~this() { writeln(number); } } void main() { Variant v = SoMany(); } DMD64 D Compiler v2.067.1 10 10 10 10 gdc (Debian 4.9.2-10) 4.9.2 10 10 For DMD I'm getting 4x10 and for gdc 2x10
May 14 2015
prev sibling next sibling parent reply "thedeemon" <dlang thedeemon.com> writes:
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote:
 Simple code:

 http://pastebin.com/raw.php?i=7jVeMFXQ

 What I'm doing wrong?
Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little basic value or a reference, like a class object, is sent it behaves unpredictably: can crash or shit garbage. Trying to send structs larger than ~20 bytes usually caused problems.
May 15 2015
parent reply "Gary Willoughby" <dev nomad.so> writes:
On Friday, 15 May 2015 at 07:51:29 UTC, thedeemon wrote:
 On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote:
 Simple code:

 http://pastebin.com/raw.php?i=7jVeMFXQ

 What I'm doing wrong?
Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little basic value or a reference, like a class object, is sent it behaves unpredictably: can crash or shit garbage. Trying to send structs larger than ~20 bytes usually caused problems.
Please raise a bugzilla issue for this.
May 15 2015
parent "Daniel Kozak" <kozzi11 gmail.com> writes:
On Friday, 15 May 2015 at 09:20:32 UTC, Gary Willoughby wrote:
 On Friday, 15 May 2015 at 07:51:29 UTC, thedeemon wrote:
 On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote:
 Simple code:

 http://pastebin.com/raw.php?i=7jVeMFXQ

 What I'm doing wrong?
Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little basic value or a reference, like a class object, is sent it behaves unpredictably: can crash or shit garbage. Trying to send structs larger than ~20 bytes usually caused problems.
Please raise a bugzilla issue for this.
this commit cause the issue: https://github.com/D-Programming-Language/phobos/commit/45fda72192ff5b878ebe915db0ffb9f6504cca8f but it is probably just a trigger not a real cause.
May 15 2015
prev sibling parent "anonymous" <anonymous example.com> writes:
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote:
 Simple code:

 http://pastebin.com/raw.php?i=7jVeMFXQ

 This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) 
 based on DMD v2.066.1 and LLVM 3.5.0.

 $ ./z
 TUQLUE
 42
 11

 Compiled by DMD v2.067.1 the program crashes:
 $ ./aa
 TUQLUE
 Segmentation fault

 What I'm doing wrong?
(Copying my reply to the post in the main group here:) I investigated this further. std.variant is to blame. I filed an issue an made a pull request to fix it: https://issues.dlang.org/show_bug.cgi?id=14585 https://github.com/D-Programming-Language/phobos/pull/3284
May 15 2015