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 — Make hashlib related modules thread-safe without the GIL · Issue #111916 · python/cpython

Make hashlib related modules thread-safe without the GIL #111916

New issue
Copy link
New issue
Copy link
Closed
#111981
Closed
Make hashlib related modules thread-safe without the GIL#111916
#111981
Copy link
Assignees
tomasr8
Labels
3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-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

The hashlib based modules already have some locking to make some operations thread-safe (with the GIL), but the logic isn't sufficient if running with the GIL disabled.

Relevant files:

  • Modules/_blake2/blake2b_impl.c
  • Modules/_blake2/blake2s_impl.c
  • Modules/_hashopenssl.c
  • Modules/hashlib.h
  • Modules/md5module.c
  • Modules/sha1module.c
  • Modules/sha2module.c
  • Modules/sha3module.c

Basic idea:

  1. Replace PyThread_type_lock lock with PyMutex. This should be both simpler and faster in general and avoid the need for dynamically assigning a lock, which can pose thread-safety issues without the GIL
  2. Add a field bool use_mutex to indicate if the code should lock the mutex. This should always be set to true in Py_NOGIL. In the default build, we should dynamically set it to true in places where we previously allocated self->lock
  3. Update ENTER_HASHLIB and EXIT_HASHLIB macros.

Linked PRs

  • gh-111916: Make hashlib related modules thread-safe without the GIL #111981
Reacted by Anthony Shaw

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.13only security fixesonly security fixes
    topic-free-threading
    on Nov 9, 2023
  2. AlexWaygood
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Nov 10, 2023
  3. tomasr8 commented on Nov 10, 2023

    @tomasr8
    tomasr8
    on Nov 10, 2023
    Member
    More actions

    Hey! I'd like to give this a try. I have a limited experience with cpython internals but I had a quick look at the code and it seems feasible to me 😅

    Reacted by Sam Gross
    Reacted by Alex Waygood
  4. colesbury
    assigned
    tomasr8
    on Nov 10, 2023
  5. colesbury commented on Nov 10, 2023

    @colesbury
    colesbury
    on Nov 10, 2023
    ContributorAuthor
    More actions

    Great, thanks! Let me know if you have any questions or there is anything I can help with.

    Reacted by Tomas R.
  6. gpshead
    closed this as completedin #111981on Nov 15, 2023
  7. gpshead
    added a commit that references this issue on Nov 15, 2023

    gh-111916: Make hashlib related modules thread-safe without the GIL (#…

    a646560
  8. aisk
    added a commit that references this issue on Feb 11, 2024

    pythongh-111916: Make hashlib related modules thread-safe without the…

    fcc7a7e
  9. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-111916: Make hashlib related modules thread-safe without the…

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

Metadata

Metadata

Assignees

  • @tomasr8
    tomasr8

Labels

3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-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.