Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-108724: Use _PyTime_GetMonotonicClock() in parking_lot.c#112222

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
vstinner wants to merge1 commit intopython:mainfromvstinner:monotonic_parking

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedNov 17, 2023
edited by bedevere-appbot
Loading

Using a system clock causes issues when it's being updated by the system administrator, NTP, Daylight Saving Time, or anything else. Sadly, on Windows, the monotonic clock resolution is around 15.6 ms.

Example:#85876

Using a system clock causes issues when it's being updated by thesystem administrator, NTP, Daylight Saving Time, or anythingelse. Sadly, on Windows, the monotonic clock resolution is around15.6 ms.Example:python#85876
@vstinner
Copy link
MemberAuthor

@colesbury@ericsnowcurrently: Please don't use the system clock for locks. It causes too many issues. Using a monotonic clock is more reliable. Sadly, on Windows, the monotonic clock has a resolution of 15.6 ms.

Copy link
Contributor

@colesburycolesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should use the monotonic clock when available, but this change isn't sufficient:

  • sem_timedwait does not work with CLOCK_MONOTONIC. (Needsem_clockwait if available)
  • pthread_cond_t needs to be initialized with the right attribute

Comment on lines +121 to 124
_PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout);
_PyTime_AsTimespec(deadline, &ts);

err = sem_timedwait(&sema->platform_sem, &ts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe:

# ifdefHAVE_SEM_CLOCKWAIT_PyTime_tdeadline=_PyDeadline_Init(timeout);_PyTime_AsTimespec_clamp(deadline,&ts);err=sem_clockwait(&sema->platform_sem,CLOCK_MONOTONIC,&ts);# else_PyTime_tdeadline=_PyTime_Add(_PyTime_GetSystemClock(),timeout);_PyTime_AsTimespec_clamp(deadline,&ts);err=sem_timedwait(&sema->platform_sem,&ts);#endif

@vstinner
Copy link
MemberAuthor

Oh. I made a mechanical change to avoid _PyTime_GetSystemClock(). I didn't see that timestamps are passed to existing functions such as pthread_cond_timedwait(). I mark my PR as a draft for now and will try to update it to address Sam's review

@vstinnervstinner marked this pull request as draftNovember 17, 2023 23:24
@vstinnervstinner deleted the monotonic_parking branchDecember 1, 2023 18:26
@vstinner
Copy link
MemberAuthor

I don't have time to fix my PR right now. I may try again later ;-)

@colesbury
Copy link
Contributor

colesbury commentedDec 1, 2023
edited
Loading

I wrote it up as an issue so that I don't forget about this and in case someone else wants to tackle it first:#112606

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@colesburycolesburycolesbury requested changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@vstinner@colesbury

[8]ページ先頭

©2009-2025 Movatter.jp