interrupting a function

Paul Backus snarwin at gmail.com
Sat Nov 17 08:17:36 UTC 2018


On Saturday, 17 November 2018 at 06:19:25 UTC, Alex wrote:
> It can happen, that the input params are correct, however, the 
> calculation lasts too long. Is there a way, to measure the 
> execution time of foo (á la benchmark) and then, if some 
> execution time limit is exceeded to interrupt the calculation? 
> At best, with a flag, whether foo ended normally or because of 
> the interruption.

You could run the calculation in another thread and use 
std.concurrency.receiveTimeout [1] to stop waiting for the result 
after a certain amount of time.

[1] https://dlang.org/phobos/std_concurrency.html#.receiveTimeout


More information about the Digitalmars-d-learn mailing list