Skip to main content

Synchronized

Struct Synchronized 

Source
pub struct Synchronized<T>(/* private fields */);
Expand description

A Send and Sync wrapper for Z3 structures associated with a Context.

This wrapper takes in a Z3 type (or a user-defined type that uses Z3 types) and translates its contents into a private “singleton” Context. Since this Context is unused elsewhere, it is safe to Send it and its contents to other threads AND to have Sync accesses across threads. The safety of the Send impl is upheld by construction, as all data associated with the inner Context is guaranteed to be moved with it. The safety of the Sync impl is upheld through an inner Mutex.

Inner data can only be accessed through Synchronized::recover, which translates the contents for the given Context.

§Performance

Initializing this type (usually done through PrepareSynchronized::synchronized) will allocate a new Context and Translate the provided T into it. This involves a non-zero amount of overhead; if you are creating thousands of Synchronized, you will see a performance impact.

If you need to move/reference a collection of data between threads, consider putting it in a Vec, which also implements PrepareSynchronized, and will only create one Context. You can also implement Translate on your own types, which will then inherit from a blanket impl of PrepareSynchronized for Translate.

Note that this will only alleviate the overhead of allocating many Contexts. There is still some unavoidable overhead:

Z3 translation scales in proportion to the complexity of the statement; if you use this with some very complex set of formulas, expect it to take longer.

§See also:

Implementations§

Source§

impl<T: Translate> Synchronized<T>

Source

pub fn new(data: &T) -> Self

Creates a new handle that is Send and Sync, allowing for easily moving your z3 structs to other threads. Data passed in here is translate’d into a one-off Context and is then put in a Mutex, allowing it to be moved and referenced across threads soundly. None of this effects the original data.

Source§

impl<T: Translate> Synchronized<T>

Source

pub fn recover(&self) -> T

Unwrap the SendableHandle, translate its contents for the given Context and return the inner data.

Trait Implementations§

Source§

impl<T: Translate> Clone for Synchronized<T>

Cloning a Synchronized will create a new Context and translate the data into it. This allows a handle to be easily sent to multiple threads without violating context memory safety, at the expense of some extra cloning.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Synchronized<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Translate> Send for Synchronized<T>

The Context inside is only used with the Translate inside, so it is sound to Send

Source§

impl<T: Translate> Sync for Synchronized<T>

The only method access to the Ast or Context is guarded by a Mutex, so it is sound to Sync

Auto Trait Implementations§

§

impl<T> !Freeze for Synchronized<T>

§

impl<T> RefUnwindSafe for Synchronized<T>

§

impl<T> Unpin for Synchronized<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Synchronized<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Synchronized<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.