-
Notifications
You must be signed in to change notification settings - Fork 25
Unknown feature horizon_thread_ext
and related thread errors
#82
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
Comments
We are still working towards merging threading support in the Rust’s ecosystem, but there are some issues we must first resolve with the API team. As such, the feature you wanted to use isn’t available yet, but you can test it out regardless by using this branch: https://github.com/AzureMarker/rust-horizon/tree/feature/horizon-threads I suggest not trying any long-term projects with this API in mind since it could very easily change. |
I just stumbled upon the same problem and implemented the use ctru::prelude::*;
use std::time::Duration;
use std::ffi::c_void;
fn get_thread_priority(thread_handle: ctru_sys::Handle) -> i32 {
unsafe {
let mut prio = 0;
let _ = ctru_sys::svcGetThreadPriority(&mut prio, thread_handle);
prio
}
}
extern "C" fn thread_function(arg: *mut c_void) {
let ix = unsafe { Box::from_raw(arg as *mut usize) };
let sleep_duration = Duration::from_millis(1000 + (*ix as u64) * 250);
let mut i = 0;
let child_prio = get_thread_priority(ctru_sys::CUR_THREAD_HANDLE);
println!("\nThread {} priority: {}\n", *ix, child_prio);
loop {
println!("Thread {} says {}", *ix, i);
i += 1;
std::thread::sleep(sleep_duration);
}
}
fn main() {
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
let _console = Console::new(gfx.top_screen.borrow_mut());
let main_prio = get_thread_priority(ctru_sys::CUR_THREAD_HANDLE);
println!("Main thread priority: {}\n", main_prio);
for ix in 0..3 {
let ix_ptr = Box::into_raw(Box::new(ix)) as *mut c_void;
let thread = unsafe {
ctru_sys::threadCreate(
Some(thread_function),
ix_ptr,
8 * 1024,
main_prio - 1,
-2,
true,
)
};
if !thread.is_null() {
println!("Created thread {ix}");
} else {
println!("Failed to create thread {ix}");
}
}
println!("\x1b[29;17HPress Start to exit");
while apt.main_loop() {
gfx.wait_for_vblank();
hid.scan_input();
if hid.keys_down().contains(KeyPad::START) {
break;
}
}
} Reference: https://rust3ds.github.io/ctru-rs/crates/ctru_sys/fn.threadCreate.html What's the current status of threading support in the Rust ecosystem? |
@Jasmin68k Using the raw API exposed by Last time this was "discussed" (but the discussion itself doesn't seem to be taken further) was in this proposal for a |
@Meziu I read through the discussion and also a few earlier ones it referenced. I now have a better understanding of the intricacies involved. Yet, I don't understand your comment. What you're saying is, currently, I can spawn a thread with But using How would I get the proper thread handle for On that note, I read in rust-lang/libs-team#195 (comment) that thread affinity can only be set before spawning? Then what does Please elaborate. |
There is no way to get a thread handle with the |
Exactly. The Rust
That's not a limitation of the Rust
You can look at
As said above, that function simply does not work on the system. Hope that clarifies things a bit. 👍 Edit: |
Thank you, that clarifies it well :) I should not have skimped over the It's nice to be able to use Of course, having all of this abstracted away as in the proposal would be much better even. |
Ran
cargo 3ds run --address 192.168.1.2 --example thread-basic --features="std-threads"
and there are 4 errors:Any ideas why? Pointers appreciated :)
The text was updated successfully, but these errors were encountered: