std1.0.0-beta-7 SafeC docs

Module async::sync

#include <std/async/sync.h> source

async: Mutex, Semaphore, Notify, cancellation

Synchronization whose waiting is a future (tokio::sync's Mutex, Semaphore, Notify, and tokio_util's CancellationToken). Waiting tasks are Pending with their waker registered, never a blocked thread; every operation takes the primitive's spinlock, so they work across tasks, executors and threads. Nothing allocates. Like channels, a primitive must not move while futures from it exist.

SafeC has no destructors, so there are no lock guards: whoever completes a lock()/acquire() future owns the lock/permits and calls unlock() / release() itself (holding them across awaits is what these are for).

self.lk = mtx.lock();          AWAIT(1, self.lk);   ... mtx.unlock();
self.acq = sem.acquire(2);     AWAIT(2, self.acq);  ... sem.release(2);
self.n = notify.notified();    AWAIT(3, self.n);    // notify.notify_one() elsewhere
self.c = token.cancelled();    AWAIT(4, self.c);    // token.cancel() elsewhere

struct Cancellable<struct Fetch, int> w = with_cancel(Fetch::new(), &token);
AWAIT_INTO(5, self.res, self.w);   // ?int: null if the token was cancelled first

Structs

AsyncMutex
MutexLock
AsyncSemaphore
SemAcquire
AsyncNotify
Notified
CancelToken
Cancelled
Cancellable'inner' until it finishes or 'token' is cancelled, whichever is first; on cancellation 'inner' is dropped. Output: ?T, null if cancelled.

Functions

with_cancel

Macros

CANCEL_DEPTH