4 ms·
Generally for more complex systems, an improbable failure mode becomes a certitude. In general, in C/C++ one needs to accept many popular libraries slowly leak
by Joel_Mckay 4y ago
Generally for more complex systems, an improbable failure mode becomes a certitude.
In general, in C/C++ one needs to accept many popular libraries slowly leak memory, bad design fragments memory, and thread-safe is often not the norm. However, for long running tasks there are several methods to mitigate the problems.
1. Add a watchdog-timer thread that garbage collects its peer even in a single process thread-unsafe program. The design requires every thread has a sleeping watchdog-timer monitor peer with a shared structure containing a mutex, peer thread ID, counter variable, periodic polling sleep interval, and error message handler. This means for n threads, there will always be 2*n +1 threads allocated, and n+1 sleeping most of the cycles (low lock contention). The watchdog timer is reset before entering a loop, or key data access/mutation operations. i.e. if there is a cycle formed in the thread(s) that locks up, than >1 watchdog timer threads is guaranteed to trip the timeout event as it breaks the expected run-time limit.
2. set transaction call quota limits, and cleanly restart a new instance of a program at regular intervals. Even with ECC ram this is highly recommended.
3. external queuing pattern with transaction confirmation, timeouts, thumb-printing, and GUID. i.e. when data is corrupted/hanged, the system redirects the task to an error handler/counter.
Happy computing, =)