pub struct Spin<T> {
lock: AtomicBool,
value: UnsafeCell<T>,
}
Expand description
By the use of Spinlocks, it is possible to serialize blocks of code
that might run parallel on multiple CPU cores.
Synchronization is implemented using a lock variable. Once a thread enters
the critical area, it sets the lock variable (to a non-zero value); when
this thread leaves the critical area, it resets the lock variable to zero.
When trying to enter an already locked critical area, the trying thread
actively waits until the critical area is free again.
Wrap the mutable data inside an unsafe cell, so that the compiler doesn’t optimize it away
Create a new spin lock, protecting value
Locks the lock and returns the protected data.
The data is wrapped in a guard, that unlocks the lock if it goes out of scope.
If you really want to unlock it. This is not protected by race conditions!
If you really want to access the contents. This is not protected by race conditions!
Formats the value using the given formatter.
Read more
Returns the “default value” for a type.
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.