Problems with receive
Bob Cowdery
bob at bobcowdery.plus.com
Sun Aug 29 12:44:11 PDT 2010
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.
More information about the Digitalmars-d-learn
mailing list