在 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.
[1] https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep -- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
