Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easy_lock: use Sleep(1) for thread yield on old Windows #16048

Closed
wants to merge 1 commit into from

Conversation

jay
Copy link
Member

@jay jay commented Jan 19, 2025

  • 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: #16037 (comment)
Ref: https://devblogs.microsoft.com/oldnewthing/20051004-09/?p=33923

Closes #xxxx

- 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: curl#16037 (comment)
Ref: https://devblogs.microsoft.com/oldnewthing/20051004-09/?p=33923

Closes #xxxx
@jay jay added the Windows Windows-specific label Jan 19, 2025
@jay jay requested a review from vszakats January 19, 2025 06:18
@jay jay closed this in 789c7f1 Jan 21, 2025
@jay jay deleted the easy_lock_xp branch January 21, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

3 participants