pub type ThreadSimpleFnPtr = dyn Fn() -> Result<ThreadParam> + Send + Sync + 'static;Expand description
All OSAL trait definitions for advanced usage. Simple thread function pointer type without parameters.
Used for basic thread functions that don’t need access to the thread handle or parameters. This is the simplest form of thread callback.
§Trait Bounds
The function must be Send + Sync + 'static to be safely used in a
multi-threaded environment.
§Examples
use osal_rs::os::*;
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};
static RUNS: AtomicU32 = AtomicU32::new(0);
let mut thread = Thread::new("simple", 1024, 1);
let worker = thread.spawn_simple(|| {
for _ in 0..3 {
RUNS.fetch_add(1, Ordering::SeqCst);
System::delay(5);
}
Ok(Arc::new(()))
}).unwrap();
worker.delete(); // waits for the thread to finish
assert_eq!(RUNS.load(Ordering::SeqCst), 3);