Expand description
Native threads with deadlock detection.
This module provides a drop-in replacement for std::thread with additional
deadlock detection capabilities. It re-exports all items from std::thread
and overrides key functions like spawn to include tracking.
§Usage
use deloxide::thread;
let handle = thread::spawn(|| {
println!("Hello from a tracked thread!");
42
});
let result = handle.join().unwrap();
assert_eq!(result, 42);
// All std::thread functions are available
thread::yield_now();
thread::sleep(std::time::Duration::from_millis(100));
let current = thread::current();Structs§
- Access
Error - An error returned by
LocalKey::try_with. - Builder
- Thread factory, which can be used in order to configure the properties of a new thread.
- Join
Handle - An owned permission to join on a thread (block on its termination).
- Local
Key - A thread local storage (TLS) key which owns its contents.
- Scope
- A scope to spawn scoped threads in.
- Scoped
Join Handle - An owned permission to join on a scoped thread (block on its termination).
- Thread
- A handle to a thread.
- Thread
Id - A unique identifier for a running thread.
Functions§
- available_
parallelism - Returns an estimate of the default amount of parallelism a program should use.
- current
- Gets a handle to the thread that invokes it.
- panicking
- Determines whether the current thread is unwinding because of panic.
- park
- Blocks unless or until the current thread’s token is made available.
- park_
timeout - Blocks unless or until the current thread’s token is made available or the specified duration has been reached (may wake spuriously).
- scope
- Creates a scope for spawning scoped threads with deadlock detection.
- sleep
- Puts the current thread to sleep for at least the specified amount of time.
- spawn
- Spawns a new thread with deadlock detection, returning a
JoinHandlefor it. - yield_
now - Cooperatively gives up a timeslice to the OS scheduler.