Uh oh!
There was an error while loading. Please reload this page.
Adds thread-safety for trees that are accessed on only one thread - #100
Adds thread-safety for trees that are accessed on only one thread#100PTNobel wants to merge 1 commit into
Conversation
PTNobel
commented
Jun 19, 2026
This is I think the only PR needed on the base engine to make the python library support free-threading. |
PTNobel
commented
Jun 20, 2026
Honestly, I think we should move to C17 or C23. I don't think we gain anything from the old standards |
dance858
commented
Jun 21, 2026
Can you explain what you are trying to do? |
PTNobel
commented
Jun 22, 2026
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. |
|
f5549f4 to
7f8e515ComparePTNobel
commented
Jun 22, 2026
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. |
rileyjmurray
commented
Sep 4, 2026
Ping @dance858. Let us know if you'd prefer that we fork SparseDiffEngine into the cvxpy org so we can work without waiting on you. I haven't checked with the other maintainers (even Parth), but I imagine we'd be happy to do so. Just let us know! |
dance858
commented
Sep 5, 2026
Hi Riley, thanks for pinging me. William and I are actively developing SparseDiffEngine, so there's no need to fork it. In the future, we appreciate a direct ping before proposing to fork a library you two haven't been involved in developing. On thread safety: I merged a fix in #118 that fixes this without introducing thread-local state, so I'm closing this PR. Thanks for identifying this issue Parth. Let me know if you have any questions |
rileyjmurray
commented
Sep 5, 2026
Thanks for the reply, Daniel. Glad to hear this is fixed, and without the thread-local state! I hadn't looked through the thread to see the lack a prior ping. My apologies for that oversight. I'll also be sure to ping William if SparseDiffEngine concerns come up in the future. |
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.