On Friday 25 September 2026 17:23:04 Lasse Collin wrote: > On 2026-09-22 LIU Hao wrote: > > 在 2026-9-21 22:57, Lasse Collin 写道: > > > On 2026-09-18 LIU Hao wrote: > > >> As for the critical section part, I think one can use dumb locks by > > >> defining `USE_WIN32_SL`; it avoids allocation and dynamic > > >> initialization. > > > > > > The macro calls Sleep(): > > > > > > #define ACQUIRE_DTOA_LOCK(n) \ > > > while (InterlockedCompareExchange (&dtoa_sl[n], 1, 0) != 0) \ > > > Sleep (0); > > > > > > Is it *guaranteed* that other threads will run before Sleep() > > > returns? On a single-processor system, it could deadlock if the > > > scheduler doesn't always switch to another thread on Sleep(0). It > > > might be fine, I'm only asking because I don't know. > > > > > > When the lock is held, the code may call malloc(). So it's not just > > > a few simple instructions that are protected by the lock. > > > > Not necessarily. According to Microsoft documentation [1], on Windows > > XP it only yields to another thread with equal priority. It's > > probably better to call `Sleep(1)` here. > > OK, thanks! > > I'm still not sure if switching to USE_WIN32_SL is good. As discussed in > the other messages, to avoid all leaks in all cases, also freelist[] > and p5s (a linked list) need to be freed, and CRITICAL_SECTIONs could > be destroyed there too. But in practice the gdtoa code often only needs > the statically-allocated private_mem[], so in many cases the > CRITICAL_SECTIONs are the only leaks. > > I did some simple benchmarking of snprintf(..., "%.*f", prec, num). > Without cache, it can be 30-150 % slower. It depends on the number > being formatted. So keeping the cache (and thus the locking) seems > worth it, if Pali or someone else can implement the cleanup to only run > on FreeLibrary().
I have some other changes for crtdll.c / tls stuff which touches same code paths. After that I can look at it (to prevent conflicts). > By the way, UCRT's snprintf speed was within 20 % of mingw-w64's > snprintf when the formatting precision was sensible, but mingw-w64's > version was 3-4 times slower than UCRT when the precision was from a > thousand to a hundred thousand (such precision would be silly in real > use). > > -- > Lasse Collin _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
