]> git.ipfire.org Git - thirdparty/curl.git/commit
easy_lock: use Sleep(1) for thread yield on old Windows
authorJay Satiro <raysatiro@yahoo.com>
Sun, 19 Jan 2025 06:18:23 +0000 (01:18 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Tue, 21 Jan 2025 06:45:21 +0000 (01:45 -0500)
commit789c7f1b6c02e9af7919dfcdb0c59499e630dda9
tree8565121f9d7ad2d2dedaa9077560cb64eaf594e4
parent7c039292ad955db327dce4e9e6a3f612ddef3c58
easy_lock: use Sleep(1) for thread yield on old Windows

- Prefer Sleep(1) over sched_yield() for pre-Vista thread yield.

On Windows sched_yield is often implemented as Sleep(0) which only
yields to threads of highest priority to current priority. However,
during libcurl initialization if there is thread contention then it's
possible that there is a wait for a different library or OS thread of
a lesser priority and then the yield is not effective during that time.
On the other hand Sleep(1) will wait the minimum time slice which is
usually like 15ms or more.

Prior to this change 2c4bfef removed sched_yield detection on Windows,
which effectively removed the yield in the spin lock, and therefore this
change restores the yield but in a different way.

For Windows Vista and later we use SRW locks and do not have this issue.

Ref: https://github.com/curl/curl/pull/16037#issuecomment-2600161764
Ref: https://devblogs.microsoft.com/oldnewthing/20051004-09/?p=33923

Closes https://github.com/curl/curl/pull/16048
lib/easy_lock.h