From a Separate Thread

The saving of coverage data can be off-loaded to a separate thread, which wakes up periodically and activates the saving. If the program runs forever or if it crashes, the coverage data up to the last saving point is available.

The instrumentation can be done for example like this:
ctcwrap ... -C OPT_ADD_COMPILE+-DCTC_LAUNCH_APPENDER \
-C LIBRARY+appendtrigger.obj make ...

The idea here is that under these settings the instrumented code (once per each instrumented file) calls the function ctc_append_trigger(). You have to provide implementation for it in some library or object file (here appendtrigger.obj), and ctc adds it to the linkage of the instrumented executable. The appendtrigger.c file needs to be compiled as C code (not as C++ code).

The appendtrigger.c file could look as follows:
/* Example for appendtrigger.c */
#include "ctc.h"
void ctc_append_trigger(void) { /* must have this name */
   static int first_time = 1;
   if (first_time == 1) {
      first_time = 0;
      ...launch_a_thread_from_the below_function;
   }
   return;
}
void the_thread_function(void) { /* the side-thread */
   while (1) {
      ...sleep_a_while; /* you determine how long */
      ctc_append_all(); /* activate the saving    */
   }
   return;
}

This schematic code shows the idea. You need to implement this in a way appropriate for the operating system you are using. Instead of really activating the coverage data saving at each wake-up round, you can implement some additional logic when and if the saving is really done.

In this arrangement no source files need to be modified.