Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Thread safety of PyCapsule #145563

Copy link
Copy link
@eendebakpt

Description

@eendebakpt
Issue body actions

Bug report

Bug description:

The PyCapsule object is not thread-safe. For example the read and write operations to the underlying pointer do not use atomics.

return capsule->pointer;

This can be fixed with atomic read and write operations. (same for the name field and some others)

Another potential issue is that some operations on a capsule are not atomic. For example a thread can attempt to retrieve a pointer using PyCapsule_GetPointer while a concurrent thread is updating the name and pointer using PyCapsule_SetName and PyCapsule_SetPointer. That could be addressed with locks, but I suspect that is too heavy for the capsule object.

I am leaning towards adding atomics for the read and write operations and documenting that in a PyCapsule does not guarantee its methods are atomic.

@colesbury @seberg

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.