What wrong?

sclytrack via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 5 00:41:03 PDT 2015


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
*/


More information about the Digitalmars-d-learn mailing list