Failed to spawn thread PermissionDenied

⚓ Rust    📅 2025-10-22    👤 surdeus    👁️ 3      

surdeus

A C# application with an Avalonia desktop user interface calls a Rust library function via Rust's Foreign Function Interface (FFI). When the application is run from an IDE (JetBrains Rider or Visual studio) in Windows, the Rust library function panics on calling std::thread::spawn. The error message is

thread '<unnamed>' panicked at ... .rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\thread\mod.rs:729:
failed to spawn thread: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }

The problem does not occur when the application is run directly rather than via an IDE. Nor does it occur when the same Rust library function is called in via an IDE in a console application or unit tests.

The workaround is to use tokio::spawn instead of std::thread::spawn.

I'd prefer not to be dependent on the tokio runtime, as the Rust library has no other use for it. Perhaps that should not really be of concern. But I thought I should report this error anyway.

I realise this may not be a Rust problem. But I reckon this forum is a good first place to get advice.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed