Skip to content
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

feat: thread initialization for reverse FFI #3632

Merged
merged 1 commit into from
Mar 7, 2024
Merged

Conversation

Kha
Copy link
Member

@Kha Kha commented Mar 7, 2024

Makes it possible to properly allocate and free thread-local runtime resources for threads not started by Lean itself

Makes it possible to properly allocate and free thread-local runtime
resources for threads not started by Lean itself
@Kha Kha requested a review from leodemoura March 7, 2024 13:45
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Mar 7, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Std/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 6af7a01af643e82e1deeb6b7523b8099d177b159 --onto 611b1746896bbadf459c00cc218fa31cf51b4e08. (2024-03-07 14:02:33)

@Kha Kha added this pull request to the merge queue Mar 7, 2024
Merged via the queue into leanprover:master with commit 3921257 Mar 7, 2024
10 checks passed
@digama0
Copy link
Collaborator

digama0 commented Mar 8, 2024

Wondering if you noticed #2464 ...

@Kha
Copy link
Member Author

Kha commented Mar 8, 2024

@digama0 Oh no, I didn't remember that one... I'd like to start small driven by practical needs, e.g. lean_finalize* seems unobjectionable to me but thread finalizers are a bit more fringe and I don't even know whether post finalizers will stay around

@Kha Kha deleted the thread-init branch March 8, 2024 12:21
@digama0
Copy link
Collaborator

digama0 commented Mar 8, 2024

There is more info on the Zulip thread. The basic motivation is that FFI should be able to do all the same lifecycle things that lean does so that it can correctly initialize lean code when lean is not running the show. This has in fact stopped some FFI projects of mine with no recourse. As an example where thread finalizers are needed, suppose there is a lean object stored in some thread local state which is not managed by lean. This object will not be cleaned up properly when the thread goes down and may corrupt lean if the same CPU is reused for another thread.

If we get rid of post_finalize then they would also disappear from this interface; I don't think there is any stability promised in that regard.

@Kha Kha restored the thread-init branch September 27, 2024 14:54
@Kha Kha deleted the thread-init branch September 27, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants