Hello!

> I think you can just do `_crt_atexit((_PVFV)(intptr_t) _flushall)` without 
> introducing a new function

Yeah, consider however that _flushall flushes both output and input streams. 
Flushing input streams seems to be a no-op on the UCRT, but probably discards 
data on earlier CRT libraries.

Best Regards,
Luca
________________________________________
Da: LIU Hao
Inviato: Venerdì, 19 Dicembre, 2025 09:48
A: [email protected]; Luca Bacci
Oggetto: Re: [Mingw-w64-public] Implement safe stdio flush on exit

在 2025-12-13 22:32, Luca Bacci 写道:
>  From the commit message:
>
>
> The Windows CRT flushes all stdio streams open for output
> within its DllMain handler. This is not quite safe:
>
> 1. A DLL may acquire locks on process termination, which can
>     cause instant termination.
> 2. The flushing operation itself must acquire locks, which goes
>     against the rules for DllMain on process termination.
>
> This commit adds an atexit handler that flushes all output streams
> before ExitProcess is called. This should also help with execution
> environments where ExitProcess behaves like TerminateProcess (see
> AppPolicyGetProcessTerminationMethod).
>
> Follow-up from https://github.com/msys2/MINGW-packages/issues/26646

This idea sounds correct. However I think you can just do 
`_crt_atexit((_PVFV)(intptr_t) _flushall)`
without introducing a new function, and it needs to be moved somewhere before 
`__main()`.




--
Best regards,
LIU Hao

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to