Async messages to a thread.

lindenk ztaticnull at gmail.com
Mon Jul 29 09:19:01 PDT 2013


> void foo(Tid parent) {
>     bool run = true;
>     while(run)
>     {
>          //do_some_blocking_function();
>          receiveTimeout(dur!"msecs"(0),
>              (string s){if(s == "STAHP!") run = false;}
>          );
>     }
>
>     // clean up
>     send(parent, "done");
> }
>
>
> void main()
> {
>     auto tid = spawn(&foo, thisTid);
>
>     // do stuff / wait for some condition
>
>     send(tid, "STAHP!");
>     auto msg = receiveOnly!(string)();
>     assert(msg == "done");
> }

Ah, no I mean, what if do_some_blocking_function blocks for some 
indeterminate amount of time. I would like it to exit even when 
it is currently blocking (as it could be unpredictable when it 
will stop blocking).


More information about the Digitalmars-d-learn mailing list