can't understand why code do not working

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 22 12:36:38 PDT 2014


Already 1 hour I am looking at example from 
http://ddili.org/ders/d.en/concurrency.html and my modification 
of it, and can't understand what's difference? Why it's output 
only:
1
3

and then do not do nothing!

import std.stdio;
import std.concurrency;
import core.thread;


void main()
{
    Tid wk = spawn(&worker);
    foreach(v; 1..5)
    {
     wk.send(v);
     int result = receiveOnly!int();
     writeln(result);
    }
}

void worker()
{
     int value = 0;
     value = receiveOnly!int();
     writeln(value);
     int result = value * 3;
     ownerTid.send(result);
}


More information about the Digitalmars-d-learn mailing list