Bob Cowdery wrote:
On 29/08/2010 19:17, Stanislav Blinov wrote:
Bob Cowdery wrote:
Hi
I'm trying out some very simple concurrency tests to make sure I
understand how it operates. However I'm having a few problems. I'm sure
this is just lack of knowledge. I dont know enough to debug these things
on my own yet.
Bob
The test below builds but does not output anything so I assume for some
reason the pattern matching is not working. If I uncomment the line
adding a variant pattern it gives me a compile error.
Error: static assert "function with arguments (VariantN!(maxSize))
occludes successive function"
But there is no successive function, its the last statement.
Also I tried using a function address instead of a literal but that
gives me a compile error:
Error: static assert (false || false) is false
From the code it looks its saying that myfunc is not a function.
import std.concurrency, std.stdio, std.variant;
int main(char[][] args)
{
auto low = 0, high = 100;
auto tid = spawn(&tfun);
foreach(i;low .. high) {
tid.send(thisTid,i);
}
writeln("Exiting");
return 0;
}
void myfunc(double x) {
writeln("Got : ", x);
}
void tfun() {
receive(
//&myfunc,
(int x) {writeln("Got : ", x);}//,
//(Variant any) {writeln("Got : ", any);}
);
};
I'm not sure about Variant part yet (never tried it myself), but as
for (int x) { /*...*/ } you've got the wrong signature. What you send
is (Tid,int), but what you're trying to receive is (int). Try changing
your tfun to receive (Tid, int x).
Thank you. I was following the book blindly without thinking, and the
book says (int x) will match 'send(tid, 5)' etc.
Well, there's no misguiding here. It's just that there are two versions
of send(), at least in current implementation. One is a free function
that gets the destination Tid as its first parameter, the other is Tid's
method. So send(tid, 5) is (almost) equivalent to tid.send(5).