GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-108724: Use _PyTime_GetMonotonicClock() in parking_lot.c by vstinner · Pull Request #112222 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Nov 17, 2023 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • Issue: Add lightweight locking C API #108724

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
pythongh-108724: Use _PyTime_GetMonotonicClock() in parking_lot.c
71a000c
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: python#85876
@vstinner vstinner added the skip news label Nov 17, 2023
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 17, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Nov 17, 2023
Add lightweight locking C API #108724
Closed
@vstinner

vstinner commented Nov 17, 2023

Copy link
Copy Markdown
Member Author

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

colesbury
colesbury requested changes Nov 17, 2023
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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. (Need sem_clockwait if available)
  • pthread_cond_t needs to be initialized with the right attribute

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
colesbury
colesbury reviewed Nov 17, 2023
View reviewed changes
Comment thread Python/parking_lot.c
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);

@colesbury colesbury Nov 17, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe:

# ifdef HAVE_SEM_CLOCKWAIT
        _PyTime_t deadline = _PyDeadline_Init(timeout);
        _PyTime_AsTimespec_clamp(deadline, &ts);
        err = sem_clockwait(&sema->platform_sem, CLOCK_MONOTONIC, &ts);
# else
        _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
        _PyTime_AsTimespec_clamp(deadline, &ts);
        err = sem_timedwait(&sema->platform_sem, &ts);
 #endif

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Nov 17, 2023

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner marked this pull request as draft November 17, 2023 23:24
@bedevere-app bedevere-app Bot removed the awaiting core review label Nov 17, 2023
@vstinner vstinner closed this Dec 1, 2023
@vstinner
vstinner deleted the monotonic_parking branch December 1, 2023 18:26
@vstinner

vstinner commented Dec 1, 2023

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 1, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@colesbury colesbury colesbury requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@vstinner @colesbury
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.