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

Review concurrency to address static_mut_refs lint #205

Open
veeenu opened this issue Oct 8, 2024 · 1 comment
Open

Review concurrency to address static_mut_refs lint #205

veeenu opened this issue Oct 8, 2024 · 1 comment
Milestone

Comments

@veeenu
Copy link
Owner

veeenu commented Oct 8, 2024

There is a new lint in nightly Clippy, static_mut_refs that is currently breaking our builds.

I wholeheartedly agree with it, I never liked having to have static mutables but unfortunately that seems to be a ubiquitous requirement for hudhook's use case.

So far, I haven't seen any reports to suggest that hudhook's clients willingly use more than one thread, and in the meantime I discovered that dear imgui itself is not thread safe.

For the time being, I will disable the lint to keep the project moving, but before long I want to evaluate different ways of managing the global state.

One possible avenue would be to move everything to Mutexes and just confine the imgui::Context into a static mut in pipeline.rs. This would add overhead in theory, though if everything keeps running from the same thread I don't see it being that impactful. Pipeline would then be the only entity responsible for passing &mut Context references around, so we can sort of stitch some form of ownership around it via other synchronization mechanisms.

Another possibility would be using thread locals but that would still require us to use mutable statics so it's not really a solution to our problem.

@veeenu
Copy link
Owner Author

veeenu commented Oct 11, 2024

  • Idea: make Pipeline be some sort of a global singleton that's only ever visible within a single spawned thread. Unsafely loan a pointer to drawlists across threads, manually managing its lifetime (it only needs to stay alive for the duration of the draw operations).
  • Idea: test whether we can ensure everything is running from the same thread and convey that constraint to the type system somehow.

@veeenu veeenu added this to the 0.9.0 milestone Nov 4, 2024
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

No branches or pull requests

1 participant