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 — Argument Clinic: Add support for PEP 703's critical sections (`Py_BEGIN_CRITICAL_SECTION()`) · Issue #111903 · python/cpython

Argument Clinic: Add support for PEP 703's critical sections (Py_BEGIN_CRITICAL_SECTION()) #111903

New issue
Copy link
New issue
Copy link
Closed
Closed
Argument Clinic: Add support for PEP 703's critical sections (Py_BEGIN_CRITICAL_SECTION())#111903
Copy link
Assignees
colesbury
Labels
3.13only security fixesonly security fixestopic-argument-clinictopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Nov 9, 2023
Issue body actions

Feature or enhancement

PEP 703 in large part relies on replacing the GIL with fine grained per-object locks. The primary way to acquire and release these locks is through the critical section API (#111569). It would be helpful if argument clinic could auto generate the API calls in the binding code when specified.

For example, the bufferedio.c will require per-object locking around most calls for thread-safety in --disable-gil builds.

As an example, the _io._Buffered.close function is written as:

cpython/Modules/_io/bufferedio.c

Lines 523 to 529 in 6f09f69

/*[clinic input]
_io._Buffered.close
[clinic start generated code]*/
static PyObject *
_io__Buffered_close_impl(buffered *self)
/*[clinic end generated code: output=7280b7b42033be0c input=d20b83d1ddd7d805]*/

We might add a @critical_section directive to designate that argument clinic should generate Py_BEGIN_CRITICAL_SECTION() and Py_END_CRITICAL_SECTION() in the binding code before calling _io__Buffered_close_impl.

/*[clinic input]
@critical_section
_io._Buffered.close
[clinic start generated code]*/

static PyObject *
_io__Buffered_close_impl(buffered *self)
/*[clinic end generated code: output=7280b7b42033be0c input=d20b83d1ddd7d805]*/

The generated binding code in bufferedio.c.h would then look like:

static PyObject *
_io__Buffered_close(buffered *self, PyObject *Py_UNUSED(ignored))
{
    PyObject *return_value = NULL;

    Py_BEGIN_CRITICAL_SECTION(self);
    return_value = _io__Buffered_close_impl(self);
    Py_END_CRITICAL_SECTION();

    return return_value;
}

Note that Py_BEGIN/END_CRITICAL_SECTION() are no-ops in the default build.

Linked PRs

  • gh-111903: Add @critical_section directive to Argument Clinic. #111904
  • gh-111903: Update AC to support "pycore_critical_section.h" header #112251
Reacted by Erlend E. Aasland
Reacted by Alex Waygood

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-argument-clinic
    3.13only security fixesonly security fixes
    topic-free-threading
    on Nov 9, 2023
  2. corona10 commented on Nov 9, 2023

    @corona10
    corona10
    on Nov 9, 2023
    Member
    More actions

    cc @erlend-aasland

    Reacted by Erlend E. Aasland
  3. colesbury commented on Nov 9, 2023

    @colesbury
    colesbury
    on Nov 9, 2023
    ContributorAuthor
    More actions

    I've updated the issue to use AC's existing "directive" feature and syntax.

    Reacted by Erlend E. Aasland
  4. colesbury
    added a commit that references this issue on Nov 9, 2023

    pythongh-111903: Add `@critical_section` directive to Argument Clinic.

    83da40a
  5. colesbury
    self-assigned this
    on Nov 9, 2023
  6. colesbury
    added a commit that references this issue on Nov 10, 2023

    Add "how to" for the critical_section Argument Clinic directive.

    088c8a1
  7. AlexWaygood
    added a commit that references this issue on Nov 14, 2023

    gh-111903: Add `@critical_section` directive to Argument Clinic. (#11…

    324531d
  8. colesbury
    closed this as completedon Nov 14, 2023
  9. AlexWaygood
    added a commit that references this issue on Nov 14, 2023

    Add "how to" for the critical_section Argument Clinic directive. (#1217)

    679d64b
  10. corona10
    added 3 commits that reference this issue on Nov 18, 2023

    pythongh-111903: Update AC to support "pycore_critical_section.h" header

    5682cf4

    pythongh-111903: Update AC to support "pycore_critical_section.h" header

    5ba260b

    gh-111903: Update AC to support "pycore_critical_section.h" header (g…

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

    pythongh-111903: Add `@critical_section` directive to Argument Clinic. (

    3e89507

    pythongh-111903: Update AC to support "pycore_critical_section.h" hea…

    0a4d64e
  12. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-111903: Add `@critical_section` directive to Argument Clinic. (

    fbabb98

    pythongh-111903: Update AC to support "pycore_critical_section.h" hea…

    84aa2f0
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 fixestopic-argument-clinictopic-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.