pub struct ThreadCounter { /* private fields */ }
Expand description
A thread-safe counter for tracking the number of active threads or operations.
This struct provides a high-level interface for incrementing, decrementing,
and waiting on a thread counter. It internally uses Arc
to allow for
cheap cloning and shared ownership.
Implementations§
Methods from Deref<Target = RawThreadCounter>§
Sourcepub fn increment(&self)
pub fn increment(&self)
Increments the thread counter.
§Note
It’s preferable to use ThreadCounter::ticket()
instead, which
ensures that the count is automatically decremented when the ticket is
dropped.
Sourcepub fn decrement(&self)
pub fn decrement(&self)
Decrements the thread counter.
If the count reaches zero, it notifies all waiting threads.
§Note
It’s preferable to use ThreadCounter::ticket()
instead, which
ensures that the count is automatically decremented when the ticket is
dropped.
Trait Implementations§
Source§impl AsRef<RawThreadCounter> for ThreadCounter
impl AsRef<RawThreadCounter> for ThreadCounter
Source§fn as_ref(&self) -> &RawThreadCounter
fn as_ref(&self) -> &RawThreadCounter
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl Clone for ThreadCounter
impl Clone for ThreadCounter
Source§fn clone(&self) -> ThreadCounter
fn clone(&self) -> ThreadCounter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for ThreadCounter
impl Default for ThreadCounter
Source§fn default() -> ThreadCounter
fn default() -> ThreadCounter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ThreadCounter
impl !RefUnwindSafe for ThreadCounter
impl Send for ThreadCounter
impl Sync for ThreadCounter
impl Unpin for ThreadCounter
impl !UnwindSafe for ThreadCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more