Threads: computationally expensive function without side effects
- Dominant language
- Rust
- Stars
- 5.2k
- Forks
- 312
- Avg merge
- 11h 10m
- Merged PRs (30d)
- 10
Description
My use case is a computationally expensive **static** function
```rust
#[godot_api]
impl Foo {
#[func] // This function is "static" - it doesn't accept self.
fn foo(a: i64, b: i64) -> i64 {...}
}
```
I want to call it from different worker pool threads from GDScript. How can I implement it in Rust?
Without `experimental-threads`, I'm getting the "must run on the main thread" exception.
With `experimental-threads`, I'm getting the function call wrapped in mutexes, making it impossible to run two functions in parallel.
This is frustrating because the code itself is demonstrably correct, it's the generated checks that are preventing me from using it the way I want to be using it.
What are my options?
Is it possible to add a feature that prevents these mutex wrappers from being emitted?
Something like
```rust
#[func(unsafe_no_emit_thread_checks)]
fn foo(...) {
// I pinky-swear to not shoot myself in the foot.
}
```
Contributor guide
Research direction
No files or tests are named. Start by tracing the generated thread checks and mutex wrappers involved when experimental-threads is enabled, then inspect how #[godot_api] and #[func] handle static functions. Done should be a documented answer about the available options or a reviewed implementation of an explicit opt-out, if that approach is accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100