[][src]Module async_std::sync

Synchronization primitives.

This module is an async version of std::sync.

Examples

Spawn a task that updates an integer protected by a mutex:

use std::sync::Arc;

use async_std::sync::Mutex;
use async_std::task;

let m1 = Arc::new(Mutex::new(0));
let m2 = m1.clone();

task::spawn(async move {
    *m2.lock().await = 1;
})
.await;

assert_eq!(*m1.lock().await, 1);

Structs

Arc

A thread-safe reference-counting pointer. 'Arc' stands for 'Atomically Reference Counted'.

Barrierunstable

A barrier enables multiple tasks to synchronize the beginning of some computation.

BarrierWaitResultunstable

A BarrierWaitResult is returned by wait when all threads in the Barrier have rendezvoused.

Mutex

A mutual exclusion primitive for protecting shared data.

MutexGuard

A guard that releases the lock when dropped.

RwLock

A reader-writer lock for protecting shared data.

RwLockReadGuard

A guard that releases the read lock when dropped.

RwLockWriteGuard

A guard that releases the write lock when dropped.

Weak

Weak is a version of Arc that holds a non-owning reference to the managed value. The value is accessed by calling upgrade on the Weak pointer, which returns an Option<Arc<T>>.