pub struct ThreadManager<'mir, 'tcx> {
    active_thread: ThreadId,
    threads: IndexVec<ThreadId, Thread<'mir, 'tcx>>,
    pub(crate) sync: SynchronizationState<'mir, 'tcx>,
    thread_local_alloc_ids: RefCell<FxHashMap<(DefId, ThreadId), Pointer<Provenance>>>,
    yield_active_thread: bool,
    timeout_callbacks: FxHashMap<ThreadId, TimeoutCallbackInfo<'mir, 'tcx>>,
}
Expand description

A set of threads.

Fields§

§active_thread: ThreadId

Identifier of the currently active thread.

§threads: IndexVec<ThreadId, Thread<'mir, 'tcx>>

Threads used in the program.

Note that this vector also contains terminated threads.

§sync: SynchronizationState<'mir, 'tcx>

This field is pub(crate) because the synchronization primitives (crate::sync) need a way to access it.

§thread_local_alloc_ids: RefCell<FxHashMap<(DefId, ThreadId), Pointer<Provenance>>>

A mapping from a thread-local static to an allocation id of a thread specific allocation.

§yield_active_thread: bool

A flag that indicates that we should change the active thread.

§timeout_callbacks: FxHashMap<ThreadId, TimeoutCallbackInfo<'mir, 'tcx>>

Callbacks that are called once the specified time passes.

Implementations§

Check if we have an allocation for the given thread local static for the active thread.

Set the pointer for the allocation of the given thread local static for the active thread.

Panics if a thread local is initialized twice for the same thread.

Borrow the stack of the active thread.

Mutably borrow the stack of the active thread.

Create a new thread and returns its id.

Set an active thread and return the id of the thread that was active before.

Get the id of the currently active thread.

Get the total number of threads that were ever spawn by this program.

Get the total of threads that are currently live, i.e., not yet terminated. (They might be blocked.)

Has the given thread terminated?

Have all threads terminated?

Enable the thread for execution. The thread must be terminated.

Get a mutable borrow of the currently active thread.

Get a shared borrow of the currently active thread.

Mark the thread as detached, which means that no other thread will try to join it and the thread is responsible for cleaning up.

allow_terminated_joined allows detaching joined threads that have already terminated. This matches Windows’s behavior for CloseHandle.

See https://docs.microsoft.com/en-us/windows/win32/procthread/thread-handles-and-identifiers:

The handle is valid until closed, even after the thread it represents has been terminated.

Mark that the active thread tries to join the thread with joined_thread_id.

Mark that the active thread tries to exclusively join the thread with joined_thread_id. If the thread is already joined by another thread, it will throw UB

Set the name of the given thread.

Get the name of the given thread.

Put the thread into the blocked state.

Put the blocked thread into the enabled state.

Change the active thread to some enabled thread.

Register the given callback to be called once the call_time passes.

The callback will be called with thread being the active thread, and the callback may not change the active thread.

Unregister the callback for the thread.

Get a callback that is ready to be called.

Wakes up threads joining on the active one and deallocates thread-local statics. The AllocId that can now be freed are returned.

Decide which action to take next and on which thread.

The currently implemented scheduling policy is the one that is commonly used in stateless model checkers such as Loom: run the active thread as long as we can and switch only when we have to (the active thread was blocked, terminated, or has explicitly asked to be preempted).

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 232 bytes