Function nstd_sys::thread::nstd_thread_spawn
source · #[no_mangle]
pub unsafe extern "C" fn nstd_thread_spawn(
thread_fn: unsafe extern "C" fn(_: NSTDOptionalHeapPtr<'_>) -> NSTDThreadResult,
data: NSTDOptionalHeapPtr<'static>
) -> Option<NSTDThread>Available on crate feature
nstd_thread only.Expand description
Spawns a new thread and returns a handle to it.
Parameters:
-
NSTDThreadResult (*thread_fn)(NSTDOptionalHeapPtr)- The thread function. -
NSTDOptionalHeapPtr data- Data to send to the thread.
Returns
NSTDThread thread - A handle to the new thread, null on error.
Safety
-
The caller of this function must guarantee that
thread_fnis a valid function pointer. -
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 {
0
}
if let Some(thread) = unsafe { nstd_thread_spawn(thread_fn, NSTDOptional::None) } {
if let NSTDOptional::Some(errc) = nstd_thread_join(thread) {
assert!(errc == 0);
}
}