Threading errors.

dcoder dcoder at devnull.dev
Mon Jul 26 08:45:56 PDT 2010


Hello.

I am working through Alexandrescu's "The D Programming Language".  He has an
example in his concurrency chapter which I can't compile.  It looks to be
missing a few import packages, but getting over that, I still can't get the
example to work:

import std.concurrency, std.stdio;
import std.contracts, std.typecons;  /* I added this */

void main() {
  auto low = 0, high = 25;
  auto tid = spawn(&writer);

  foreach( i; low .. high) {
    writeln("Main thread: ", i);
    tid.send(thisTid, i);
    enforce( receiveOnly!Tid() == tid);
  }

  return;
}

void writer() {
  for( ;; ) {
    auto msg = receiveOnly!(Tid, int)();
    writeln( "Secondary thread: ", msg[1]);
    msg[0].send(thisTid);
  }

  return;
}


I get the following compiler error:

$ dmd Thread2.d

Thread2.d(10): Error: template std.typecons.Tuple!(Tid).Tuple.opEquals(T) if
(is(typeof(T.field))) does not match any function template declaration
Thread2.d(10): Error: template std.typecons.Tuple!(Tid).Tuple.opEquals(T) if
(is(typeof(T.field))) cannot deduce template function from argument types !()(Tid)


$ dmd --help
Digital Mars D Compiler v2.042
Copyright (c) 1999-2010 by Digital Mars written by Walter Bright
Documentation: http://www.digitalmars.com/d/2.0/index.html


So, what am I doing wrong here?

thanks.



More information about the Digitalmars-d-learn mailing list