문제

I run a Visual C++ console test program inside the daily build. Every now and then the test would call some function that was changed by other developers improperly, descend into an infinite loop and hang thus blocking the build.

I need a watchdog solution as simple as possible. Here's what I came up with. In the test program entry point I start a separate thread that loops continuosly and checks elapsed time. If some predefined period is exceeded it calls TerminateProcess(). Pseudocode:

DWORD WatchDog( LPVOID)
{
     DWORD start = GetTickCount();
     while( true ) {
        Sleep( ReasonablePeriod );
        if( GetTickCount() - start > MaxAllowed ) {
            TerminateProcess( GetCurrentProcess(), 0 );
        }
     }
     return 0;
}

Is this solution any worse than a watchdog implemented as a separate master program?

도움이 되었습니까?

해결책

I think it's preferable to implement the watchdog as a separate process. It's easier to re-use it, it's easier to detect if your app crashed and to get its return code.

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