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 — parking_lot.c should use _PyTime_GetMonotonicClock() when available · Issue #112606 · python/cpython

parking_lot.c should use _PyTime_GetMonotonicClock() when available #112606

New issue
Copy link
New issue
Copy link
Closed
Closed
parking_lot.c should use _PyTime_GetMonotonicClock() when available#112606
Copy link
Assignees
mattprodani
Labels
3.13only security fixesonly security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@colesbury
colesbury
opened on Dec 1, 2023
Issue body actions

Bug report

The _PySemaphore_PlatformWait function in parking_lot.c has three implementations:

  • WaitForSingleObjectEx (for Windows)
  • sem_timedwait (Linux and most other POSIX platforms)
  • pthread_cond_timedwait (macOS and possibly other platforms that don't have sem_timedwait)

We should follow the pattern used in thread_pthread.h where we prefer functions that support CLOCK_MONOTONIC. These are sem_clockwait and pthread_cond_timedwait after setting pthread_condattr_setclock.

Additionally, we should use _PyTime_AsTimespec_clamp instead of _PyTime_AsTimespec (we don't want to raise errors in these code paths).

Note that:

  1. Windows doesn't need any changes because WaitForSingleObjectEx isn't relative to any specific clock -- it just takes a timeout for N milliseconds in the future
  2. macOS doesn't support pthread_condattr_setclock, so we're stuck with the system clock on macOS. It's not clear to me if we use the pthread_cond_timedwait for any other OS.

Linked PRs

  • gh-112606: Use monotonic clock when supported in semaphore waiting in parking_lot.c #112614
  • gh-112606: Use pthread_cond_timedwait_relative_np in parking_lot.c when available #112616
  • gh-112606: Use sem_clockwait with monotonic time when supported in parking_lot.c #112733

Activity

  1. colesbury
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.13only security fixesonly security fixes
    topic-free-threading
    on Dec 1, 2023
  2. mattprodani commented on Dec 4, 2023

    @mattprodani
    mattprodani
    on Dec 4, 2023
    Contributor
    More actions

    Splitting into two PRs for sem_timedwait and pthread_cond_timedwait implementations. Working on finishing up the condvar implementation to share fields that initialize the proper pthread_condattr_t from thread_pthread.h as per notes.

    • gh-112606: Use sem_clockwait with monotonic time when supported in parking_lot.c #112733
    • gh-112606: Use pthread_cond_timedwait_relative_np in parking_lot.c when available #112616
  3. colesbury
    assigned
    mattprodani
    on Dec 5, 2023
  4. corona10
    added a commit that references this issue on Dec 6, 2023

    gh-112606: Use sem_clockwait with monotonic time when supported in pa…

    a2a46f9
  5. vstinner commented on Dec 6, 2023

    @vstinner
    vstinner
    on Dec 6, 2023
    Member
    More actions

    As someone writes a fix for the mutex, ping me, I can review it ;-)

  6. erlend-aasland
    added a commit that references this issue on Jan 30, 2024

    gh-112606: Use pthread_cond_timedwait_relative_np() in parking_lot.c …

    e5e1866
  7. aisk
    added 2 commits that reference this issue on Feb 11, 2024

    pythongh-112606: Use sem_clockwait with monotonic time when supported…

    141cdf4

    pythongh-112606: Use pthread_cond_timedwait_relative_np() in parking_…

    646d2d1
  8. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-112606: Use sem_clockwait with monotonic time when supported…

    de99b75
  9. colesbury commented on Oct 8, 2024

    @colesbury
    colesbury
    on Oct 8, 2024
    ContributorAuthor
    More actions

    Closing this as the relevant PRs landed a while ago.

  10. colesbury
    closed this as completedon Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mattprodani
    mattprodani

Labels

3.13only security fixesonly security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — 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.