Timeout around function call
forum.dlang.org at fi.fo
Wed Sep 23 17:33:50 UTC 2020
On Tuesday, 22 September 2020 at 21:55:51 UTC, Imperatorn wrote:
> On Tuesday, 22 September 2020 at 09:32:13 UTC, drathier wrote:
>> What's the obvious way to put a timeout around a function
>> call? I'm thinking a 5 or 30 second timeout, and I'm expecting
>> it to pretty much never time out.
> You have several options. Either you use the actor model
> (spawn[Linked]) and send a termination message after a
> specified time. Or you use a task and check for
> yourTask.done(). Or you could create a Thread and check
> (You didn't specify what you wanted to happen and if blocking
> was allowed or not)
Blocking is perfectly fine. I'm wondering if I need things to be
shared now or something? Not used to programming with threads.
Adding a shared modifier recursively onto every piece of data
that needs it is a ton of work though.
I don't want to copy the data around since it's many gigabytes,
but I'm sure there won't be any data races; main thread will
start 2 threads, one for running the timer and one running the
function call. The main thread doesn't access the data until both
the timer and function call threads have stopped completely.
More information about the Digitalmars-d-learn