Skip to main content

Module thread

Module thread 

Source
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§

AccessError
An error returned by LocalKey::try_with.
Builder
Thread factory, which can be used in order to configure the properties of a new thread.
JoinHandle
An owned permission to join on a thread (block on its termination).
LocalKey
A thread local storage (TLS) key which owns its contents.
Scope
A scope to spawn scoped threads in.
ScopedJoinHandle
An owned permission to join on a scoped thread (block on its termination).
Thread
A handle to a thread.
ThreadId
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 panicking.
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 JoinHandle for it.
yield_now
Cooperatively gives up a timeslice to the OS scheduler.

Type Aliases§

Result
A specialized Result type for threads.