Index: tools/c-arcmt-test/c-arcmt-test.c =================================================================== --- tools/c-arcmt-test/c-arcmt-test.c +++ tools/c-arcmt-test/c-arcmt-test.c @@ -97,14 +97,20 @@ void thread_runner(void *client_data_v) { thread_info *client_data = client_data_v; client_data->result = carcmttest_main(client_data->argc, client_data->argv); -#ifdef __CYGWIN__ - fflush(stdout); /* stdout is not flushed on Cygwin. */ -#endif +} + +static void flush_atexit(void) { + // stdout, and surprisingly even stderr, are not always flushed on process + // and thread exit, particularly when the system is under heavy load. + fflush(stdout); + fflush(stderr); } int main(int argc, const char **argv) { thread_info client_data; + atexit(flush_atexit); + #if defined(_WIN32) if (getenv("LIBCLANG_LOGGING") == NULL) putenv("LIBCLANG_LOGGING=1"); Index: tools/c-index-test/c-index-test.c =================================================================== --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -4116,14 +4116,20 @@ void thread_runner(void *client_data_v) { thread_info *client_data = client_data_v; client_data->result = cindextest_main(client_data->argc, client_data->argv); -#ifdef __CYGWIN__ - fflush(stdout); /* stdout is not flushed on Cygwin. */ -#endif +} + +static void flush_atexit(void) { + // stdout, and surprisingly even stderr, are not always flushed on process + // and thread exit, particularly when the system is under heavy load. + fflush(stdout); + fflush(stderr); } int main(int argc, const char **argv) { thread_info client_data; + atexit(flush_atexit); + #ifdef CLANG_HAVE_LIBXML LIBXML_TEST_VERSION #endif