What wrong?
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 2 12:13:43 PDT 2015
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();
}
More information about the Digitalmars-d-learn
mailing list