Pergunta

I need to wrap a function in a timeout, using ACE in C++. This function is waiting for a response from the OS, and sometimes it does not return.

I cannot modify the function, so I cannot put the abort condition into it directly. I have to add a timeout to the function externally.

I saw a similar question for it in boost - C++: How to implement a timeout for an arbitrary function call?

however, I am using ACE.

Foi útil?

Solução

Put the function in a separate thread. If the thread hasn't exited within the timeout, then detach it and let it run to finish in the background without getting any result from it.

Note that this won't work if the function has side-effects (like writing to a file).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top