Timeout around function call

Ali Çehreli acehreli at yahoo.com
Wed Sep 23 20:44:51 UTC 2020

On 9/23/20 1:19 PM, Imperatorn wrote:

 > No. You should not share anything. Personally I would just send a
 > message to request termination or use the solution provided with timeout.

std.concurrency does not allow "mutable thread-local data"; so one needs 
to cast to shared (assuming copying is not desired e.g. because it's 
expensive). I am modifying my second program[1] with these changes:

The worker's receive() call mentions an element with shared ints:

       // .. same as before

       // New message type:
       (shared(int)[] arr) {

The sender casts to shared and receives a shared(int):

   auto arr = new int[100];
   writefln!"Received array result: %s"(receiveOnly!(shared(int))());

It is unfortunate that receiveOnly!int does not work because the 
returned int is just a copy. Well, at least we have a way of 
distinguishing int from shared(int). Is it useful?


[1] https://forum.dlang.org/post/rkdrql$2uht$1@digitalmars.com

More information about the Digitalmars-d-learn mailing list