Skip to content

fix: modify the internals pointer-to-pointer implementation to not use thread_local #5709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 3, 2025

Conversation

b-pass
Copy link
Contributor

@b-pass b-pass commented Jun 2, 2025

Description

As mentioned in #5705, there are a couple platforms that don't support C++11's thread_local keyword but they do still support Python's thread-specific-storage.

So this implementation restructures the part of sub-interpreter support that was using thread_local to instead use CPython's TSS.

To make this a little easier I added a wrapper class around the PYBIND11_TLS_* macros. This makes accessing them feel a lot more like accessing a pointer, and puts their allocation and release into RAII.

I also changed the internals use of PYBIND11_TLS (tstate and loader_life_support_tls_key members) to use the new wrapper. This was not strictly required to address the goal of the PR, but it makes sense to do this since there is a wrapper for it now.

NOTE: This should probably increment the internals ABI number, but since that was already changed for RC1, I didn't change it in this PR. Should it be changed?

Suggested changelog entry:

  • Modify internals pointer-to-pointer implementation to not use thread_local (better iOS support)

@b-pass b-pass marked this pull request as draft June 2, 2025 02:14
@b-pass b-pass marked this pull request as ready for review June 2, 2025 03:37
@henryiii
Copy link
Collaborator

henryiii commented Jun 2, 2025

I'll try to get #5705, rebase this and add a comment the removes the subinterp disable define. That should also trigger the full CI.

I think we do need an internals bump just in case people built with the old RC. @rwgk might also bump the internals once more for the reworking he proposed in #5700 (maybe next weekend?).

@henryiii henryiii force-pushed the subinterpreter-in-tss branch from dd73712 to cb9227a Compare June 2, 2025 04:31
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple comments.

I don't have the free bandwidth at the moment to fully review this. I only scrolled through and stopped here and there. I like what I'm seeing!

@henryiii please go ahead and merge this if it looks good to you. (Assuming you're bumping the internals version.)

@b-pass b-pass force-pushed the subinterpreter-in-tss branch from cb9227a to 20f3606 Compare June 2, 2025 21:06
@henryiii henryiii merged commit c7026d0 into pybind:master Jun 3, 2025
83 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jun 3, 2025
@henryiii henryiii changed the title Modify the internals pointer-to-pointer implementation to not use thread_local fix: modify the internals pointer-to-pointer implementation to not use thread_local Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs changelog Possibly needs a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants