문제

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.

도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top