Skip to content

stdlib/syncView source ↗

sync

32 items · generated by scribe fromstdlib/sync.fd· synced 2026-11-15

stdlib/sync32 items

Contents

sync_atomic_alloc

Allocate a shared atomic i64 slot, initialized to 0. Returns an address that can be used with atomic operations.

pub fn sync_atomic_alloc(initial: i64) -> i64 {

Parameters:

  • initial: i64

Returns: i64

Defined at line 22


sync_atomic_load

Atomically load the value at an address.

pub fn sync_atomic_load(addr: i64) -> i64 {

Parameters:

  • addr: i64

Returns: i64

Defined at line 29


sync_atomic_store

Atomically store a value at an address.

pub fn sync_atomic_store(addr: i64, value: i64) -> void {

Parameters:

  • addr: i64
  • value: i64

Returns: void

Defined at line 34


sync_atomic_cas

Atomically compare-and-swap. Returns true if the swap succeeded.

pub fn sync_atomic_cas(addr: i64, expected: i64, new_val: i64) -> bool {

Parameters:

  • addr: i64
  • expected: i64
  • new_val: i64

Returns: bool

Defined at line 39


sync_atomic_add

Atomically add a value. Returns the old value before the add.

pub fn sync_atomic_add(addr: i64, value: i64) -> i64 {

Parameters:

  • addr: i64
  • value: i64

Returns: i64

Defined at line 44


sync_mutex_create

Create a mutex. Returns a mutex handle.

pub fn sync_mutex_create() -> i64 {

Returns: i64

Defined at line 49


sync_mutex_lock

Lock a mutex (blocks if contended by another thread).

pub fn sync_mutex_lock(m: i64) -> void {

Parameters:

  • m: i64

Returns: void

Defined at line 54


sync_mutex_unlock

Unlock a mutex.

pub fn sync_mutex_unlock(m: i64) -> void {

Parameters:

  • m: i64

Returns: void

Defined at line 59


sync_tls_create

Create a thread-local storage key. Returns a key handle. Each thread can store its own value for this key.

pub fn sync_tls_create() -> i64 {

Returns: i64

Defined at line 80


sync_tls_get

Get the thread-local value for the current thread. Returns 0 if unset.

pub fn sync_tls_get(key: i64) -> i64 {

Parameters:

  • key: i64

Returns: i64

Defined at line 85


sync_tls_set

Set the thread-local value for the current thread.

pub fn sync_tls_set(key: i64, value: i64) -> void {

Parameters:

  • key: i64
  • value: i64

Returns: void

Defined at line 90


sync_rwlock_create

Create a reader-writer lock. Returns a handle. Allows multiple concurrent readers or one exclusive writer.

pub fn sync_rwlock_create() -> i64 {

Returns: i64

Defined at line 100


sync_rwlock_read_lock

Acquire a read lock (shared — multiple readers allowed).

pub fn sync_rwlock_read_lock(rwlock: i64) -> void {

Parameters:

  • rwlock: i64

Returns: void

Defined at line 119


sync_rwlock_read_unlock

Release a read lock.

pub fn sync_rwlock_read_unlock(rwlock: i64) -> void {

Parameters:

  • rwlock: i64

Returns: void

Defined at line 135


sync_rwlock_write_lock

Acquire a write lock (exclusive — no other readers or writers).

pub fn sync_rwlock_write_lock(rwlock: i64) -> void {

Parameters:

  • rwlock: i64

Returns: void

Defined at line 149


sync_rwlock_write_unlock

Release a write lock.

pub fn sync_rwlock_write_unlock(rwlock: i64) -> void {

Parameters:

  • rwlock: i64

Returns: void

Defined at line 157


atomic_u64_new

Create an AtomicU64 initialized to the given value.

pub fn atomic_u64_new(initial: i64) -> i64 {

Parameters:

  • initial: i64

Returns: i64

Defined at line 169


atomic_u64_load

Atomically load an AtomicU64.

pub fn atomic_u64_load(addr: i64) -> i64 {

Parameters:

  • addr: i64

Returns: i64

Defined at line 174


atomic_u64_store

Atomically store a value to an AtomicU64.

pub fn atomic_u64_store(addr: i64, value: i64) -> void {

Parameters:

  • addr: i64
  • value: i64

Returns: void

Defined at line 179


atomic_u64_fetch_add

Atomically add a value to an AtomicU64. Returns the old value.

pub fn atomic_u64_fetch_add(addr: i64, value: i64) -> i64 {

Parameters:

  • addr: i64
  • value: i64

Returns: i64

Defined at line 184


atomic_u64_cas

Atomically compare-and-swap. Returns true if successful.

pub fn atomic_u64_cas(addr: i64, expected: i64, new_val: i64) -> bool {

Parameters:

  • addr: i64
  • expected: i64
  • new_val: i64

Returns: bool

Defined at line 189


sync_spawn

Spawn a function as a new OS thread. Returns a Future handle. Use await to join the thread and get the result. The function must take i64 parameters and return i64.

pub fn sync_spawn(func_name: str, num_args: i64) -> i64 {

Parameters:

  • func_name: str
  • num_args: i64

Returns: i64

Defined at line 196


SYNC_CHAN_PENDING:

pub const SYNC_CHAN_PENDING: i64 = - 9223372036854775807;

Defined at line 219


sync_channel_create

Create a bounded channel with the given capacity. Returns a channel handle (i64).

pub fn sync_channel_create(capacity: i64) -> i64 {

Parameters:

  • capacity: i64

Returns: i64

Defined at line 222


sync_channel_send

Send a value through the channel. Blocks if the buffer is full. Returns true if the value was sent, false if the channel is closed.

pub fn sync_channel_send(ch: i64, value: i64) -> bool {

Parameters:

  • ch: i64
  • value: i64

Returns: bool

Defined at line 228


sync_channel_recv

Receive a value from the channel. Blocks if the buffer is empty. Returns the value, or SYNC_CHAN_PENDING if the channel is closed and empty.

pub fn sync_channel_recv(ch: i64) -> i64 {

Parameters:

  • ch: i64

Returns: i64

Defined at line 234


sync_channel_try_recv

Non-blocking receive. Returns the value if available, SYNC_CHAN_PENDING if the channel is empty (but not closed), or 0 if the channel is closed and empty.

pub fn sync_channel_try_recv(ch: i64) -> i64 {

Parameters:

  • ch: i64

Returns: i64

Defined at line 241


sync_channel_close

Close the channel. Signals receivers that no more values will be sent.

pub fn sync_channel_close(ch: i64) -> void {

Parameters:

  • ch: i64

Returns: void

Defined at line 246


sync_channel_is_closed

Check if the channel has been closed.

pub fn sync_channel_is_closed(ch: i64) -> bool {

Parameters:

  • ch: i64

Returns: bool

Defined at line 251


with_lock

Lock m, run f, and release the lock when f returns — including the ?-propagation and panic paths, because the release rides defer.

val m = sync_mutex_create(); val total = with_lock(m, tally);

Prefer this over manual lock/unlock pairs: it cannot forget to unlock.

pub fn with_lock(m: i64, f: fn() -> i64) -> i64 {

Parameters:

  • m: i64
  • f: fn() -> i64

Returns: i64

Defined at line 264


with_write_lock

Same, for read-write locks: holds the write lock for f’s duration.

pub fn with_write_lock(rwlock: i64, f: fn() -> i64) -> i64 {

Parameters:

  • rwlock: i64
  • f: fn() -> i64

Returns: i64

Defined at line 273


with_read_lock

Same, for read-write locks: holds the read lock for f’s duration.

pub fn with_read_lock(rwlock: i64, f: fn() -> i64) -> i64 {

Parameters:

  • rwlock: i64
  • f: fn() -> i64

Returns: i64

Defined at line 282


Generated by scribe, the Fides documentation generator