Skip to main content

ThreadToken

Struct ThreadToken 

Source
pub struct ThreadToken(/* private fields */);
Expand description

A special token asserting the liveness of a given thread.

You can create one by giving up a Tokens containing the THREAD_TOKEN namespace.

For now, it has only one special property: it can be used to express that the number of threads is bounded, in particular it is less than Self::max_live_threads. This might also be used in the future to carry thread ids.

Implementations§

Source§

impl ThreadToken

Source

pub fn max_live_threads() -> Int

Maximum number of threads that can be running simultaneously.

logic(opaque) ⚠

ensures

result < usize::MAX@ / 2

Source

pub fn get_thread_token<'a>(tokens: Tokens<'a>) -> &'a mut Self

Get a temporary thread token, that asserts that the current thread is still alive.

To ensure that there is only one such token per thread, you need to temporarily give a Tokens object containing the THREAD_TOKEN namespace.

requires

tokens.contains(THREAD_TOKEN())

ghost

Source

pub fn bound_thread_number(thread_tokens: &Seq<Self>)

Ghost lemma, to bound the total number of threads.

We are certain that it is impossible to spawn more than Self::max_live_threads threads at the same time ; and, each ThreadToken is associated to exactly one live thread.

ghost

ensures

thread_tokens.len() <= Self::max_live_threads()

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.