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 — Implement Python Critical Sections from PEP 703 · Issue #111569 · python/cpython

Implement Python Critical Sections from PEP 703 #111569

New issue
Copy link
New issue
Copy link
Closed
Closed
Implement Python Critical Sections from PEP 703#111569
Copy link
Assignees
colesbury
Labels
3.13only security fixesonly security fixesOS-wasitopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Oct 31, 2023
Issue body actions

Feature or enhancement

PEP 703 introduces the concept of "Python Critical Sections", which are an abstraction to help replace the GIL with finer grained locking. The key ideas is to replace the GIL with per-object locks and implicitly release these locks in the same places where the GIL would have been released. The mechanism is:

  1. Keep track of locked mutexes in a per-thread stack
  2. When the thread "detaches" from the interpreter (i.e., _PyThreadState_Detach()), unlock all of the thread's locked mutexes
  3. When the thread re-"attaches" to the interpreter, re-lock the top-most mutex or mutexes.

The "public" 1 API consists of four macros:

Py_BEGIN_CRITICAL_SECTION(object);
Py_END_CRITICAL_SECTION;
Py_BEGIN_CRITICAL_SECTION2(object1, object2);
Py_END_CRITICAL_SECTION2;

These will be no-ops in the default build of CPython.

Note that if you need to operate on two objects at once, then you must use the Py_BEGIN_CRITICAL_SECTION2 macro. Nesting two calls to Py_BEGIN_CRITICAL_SECTION does not guarantee that both objects are locked because the inner calls may suspend the outer critical section.

Linked PRs

  • gh-111569: Implement Python critical section API #111571
  • gh-111569: Fix critical sections test on WebAssembly #111897

Footnotes

  1. At least at the start, even these "public" macros will still be internal-only (i.e., in Include/internal). I expect that we will eventually want to make them public so that C-API extensions can make use of them. ↩

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.13only security fixesonly security fixes
    topic-free-threading
    on Oct 31, 2023
  2. colesbury
    self-assigned this
    on Oct 31, 2023
  3. colesbury
    added a commit that references this issue on Oct 31, 2023

    pythongh-111569: Implement Python critical section API

    6bf34f5
  4. ericsnowcurrently
    added a commit that references this issue on Nov 8, 2023

    gh-111569: Implement Python critical section API (gh-111571)

    31c90d5
  5. brettcannon
    added
    OS-wasi
    on Nov 9, 2023
  6. brettcannon commented on Nov 9, 2023

    @brettcannon
    brettcannon
    on Nov 9, 2023
    Member
    More actions

    The latest PR related to this change broke the WebAssembly buildbots by causing them to time out: https://buildbot.python.org/all/#/builders/1046/builds/3456/steps/11/logs/stdio .

  7. colesbury
    added a commit that references this issue on Nov 9, 2023

    pythongh-111569: Fix critical sections test on WebAssembly

    aef9180
  8. brettcannon
    added a commit that references this issue on Nov 9, 2023

    gh-111569: Fix critical sections test on WebAssembly (GH-111897)

    289af86
  9. colesbury
    closed this as completedon Nov 9, 2023
  10. aisk
    added 2 commits that reference this issue on Feb 11, 2024

    pythongh-111569: Implement Python critical section API (pythongh-111571)

    7907203

    pythongh-111569: Fix critical sections test on WebAssembly (pythonGH-…

    41586cd
  11. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-111569: Implement Python critical section API (pythongh-111571)

    3b0497b

    pythongh-111569: Fix critical sections test on WebAssembly (pythonGH-…

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

Metadata

Metadata

Assignees

  • @colesbury
    colesbury

Labels

3.13only security fixesonly security fixesOS-wasitopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.