diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs new file mode 100644 index 0000000..a96d15f --- /dev/null +++ b/ctru-rs/examples/thread-basic.rs @@ -0,0 +1,47 @@ +use ctru::console::Console; +use ctru::gfx::Gfx; +use ctru::services::apt::Apt; +use ctru::services::hid::{Hid, KeyPad}; +use ctru::thread; + +use std::time::Duration; + +fn main() { + // Initialize services + ctru::init(); + let apt = Apt::init().unwrap(); + let hid = Hid::init().unwrap(); + let gfx = Gfx::default(); + let _console = Console::init(gfx.top_screen.borrow_mut()); + + let prio = thread::current().priority(); + println!("Main thread prio: {}\n", prio); + + for ix in 0..3 { + thread::Builder::new() + .priority(prio - 1) + .spawn(move || { + let sleep_duration: u64 = 1000 + ix * 250; + let mut i = 0; + loop { + println!("Thread{ix} says {i}"); + i += 1; + thread::sleep(Duration::from_millis(sleep_duration)); + } + }) + .unwrap(); + + println!("Created thread {ix}"); + } + + while apt.main_loop() { + gfx.flush_buffers(); + gfx.swap_buffers(); + gfx.wait_for_vblank(); + + hid.scan_input(); + if hid.keys_down().contains(KeyPad::KEY_START) { + break; + } + } +} diff --git a/ctru-rs/src/thread.rs b/ctru-rs/src/thread.rs index e12a554..225b1f8 100644 --- a/ctru-rs/src/thread.rs +++ b/ctru-rs/src/thread.rs @@ -10,8 +10,7 @@ //! 3DS-specific threading API //! -//! While it is possible to create threads on the 3DS using functions found in -//! `std::thread`, the standard API does not expose the ability to set a thread's +//! The standard API does not expose the ability to set a thread's //! priority level and to pin a thread to a specific CPU core. This module exists //! to address those and other shortcomings. //!