Skip to content

Adds thread-safety for trees that are accessed on only one thread#100

Open
PTNobel wants to merge 1 commit into
SparseDifferentiation:mainfrom
PTNobel:prep-for-thread-safety
Open

Adds thread-safety for trees that are accessed on only one thread#100
PTNobel wants to merge 1 commit into
SparseDifferentiation:mainfrom
PTNobel:prep-for-thread-safety

Conversation

@PTNobel

@PTNobel PTNobel commented Jun 19, 2026

Copy link
Copy Markdown

Best I can tell from going through the code, the only state that is shared across trees is the alloc variables; so this makes them thread locals.

To access thread locals, I bump the C version to C11. Every platform CVXPY supports supports C11, so I figured this would be not an issue. LMK if I am worng.

@PTNobel

PTNobel commented Jun 19, 2026

Copy link
Copy Markdown
Author

This is I think the only PR needed on the base engine to make the python library support free-threading.

@PTNobel

PTNobel commented Jun 20, 2026

Copy link
Copy Markdown
Author

Honestly, I think we should move to C17 or C23. I don't think we gain anything from the old standards

@dance858

Copy link
Copy Markdown
Collaborator

Can you explain what you are trying to do?

@PTNobel

PTNobel commented Jun 22, 2026

Copy link
Copy Markdown
Author

I'm trying to add free threading support to CVXPY. This means we need to have a thread safety story for all our dependencies. Looking through this library, it seemed to have only one dependency on shared state, so I was trying to eliminate that so we could have a clear thread safety story here.

I will then add free-threading support in the Python bindings.

@PTNobel

PTNobel commented Jun 22, 2026

Copy link
Copy Markdown
Author

I'm a little confused what is wrong in CI... It worked locally Fixed. I forgot to push one file.

@PTNobel PTNobel force-pushed the prep-for-thread-safety branch from f5549f4 to 7f8e515 Compare June 22, 2026 00:49
@PTNobel

PTNobel commented Jun 22, 2026

Copy link
Copy Markdown
Author

I think my expectation at this point is "if a expression tree is only ever accessed from one thread, this library is thread-safe" would be the story I'm after here. We'll have to do some locking at the python level; but I think this would be a good start to get rid of the obvious issues.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants