#[unsafe(no_mangle)]pub unsafe extern "C" fn nstd_thread_spawn(
thread_fn: unsafe extern "C" fn(NSTDOptionalHeapPtr<'_>) -> NSTDThreadResult,
data: NSTDOptionalHeapPtr<'static>,
desc: Option<&NSTDThreadDescriptor>,
) -> NSTDOptionalThreadAvailable on crate feature
thread only.Expand description
Spawns a new thread executing the function thread_fn and returns a handle to the new thread.
§Parameters:
-
NSTDThreadResult (*thread_fn)(NSTDOptionalHeapPtr)- The thread function. -
NSTDOptionalHeapPtr data- Data to send to the thread. -
const NSTDThreadDescriptor *desc- The thread descriptor. This value may be null.
§Returns
NSTDOptionalThread thread - A handle to the new thread on success, or an uninitialized “none”
variant on error.
§Safety
-
The caller of this function must guarantee that
thread_fnis a valid function pointer. -
This operation can cause undefined behavior if
desc.name’s data is invalid. -
The data type that
dataholds must be able to be safely sent between threads.
§Example
use nstd_sys::{
core::optional::NSTDOptional,
heap_ptr::NSTDOptionalHeapPtr,
thread::{nstd_thread_join, nstd_thread_spawn, NSTDThreadResult},
};
unsafe extern "C" fn thread_fn(data: NSTDOptionalHeapPtr) -> NSTDThreadResult {
NSTDOptional::None
}
let thread = unsafe { nstd_thread_spawn(thread_fn, NSTDOptional::None, None) };
if let NSTDOptional::Some(thread) = thread {
if let NSTDOptional::Some(ret) = unsafe { nstd_thread_join(thread) } {
if let NSTDOptional::Some(_) = ret {
panic!("this shouldn't be here");
}
}
}