XU XUv0.8.8
中文

API

#sync

import: #sync

counts: 9 fns, 15 methods, 5 types, 0 consts, 0 ifaces

Mutex / WaitGroup / Once / RWMutex / Cond and atomic int.

struct Mutex

XuAPI
pub struct Mutex {
    pub tok chan int
}

Purpose

Mutex and WaitGroup are owning channel handles, not user-visible pointers and not atomic.Pointer. The token lives in the runtime channel object copies of Mutex share that object (like channel variables). Protected data still must move through channels — &mut must not cross xu (S6).

Parameters

tok chan int
field (channel; type chan int)

struct WaitGroup

XuAPI
pub struct WaitGroup {
    pub done chan int
    pub pending int
}

Purpose

Public struct `WaitGroup`.

Parameters

done chan int
field (channel; type chan int)
pending int
field (int)

mutex

XuAPI
pub fn mutex() Mutex

Purpose

mutex; returns Mutex.

Parameters

none

Returns

Mutex — a value of this type

(&mut Mutex) lock

XuAPI
pub fn (m &mut Mutex) lock()

Purpose

Method on `&mut Mutex`: acquire the lock.

Parameters

m &mut Mutex
receiver &mut Mutex (exclusive borrow)

(&mut Mutex) unlock

XuAPI
pub fn (m &mut Mutex) unlock()

Purpose

Method on `&mut Mutex`: release the lock.

Parameters

m &mut Mutex
receiver &mut Mutex (exclusive borrow)

wait_group

XuAPI
pub fn wait_group() WaitGroup

Purpose

Wait group.

Parameters

none

Returns

WaitGroup — a value of this type

(&mut WaitGroup) add

XuAPI
pub fn (w &mut WaitGroup) add(delta int)

Purpose

Method on `&mut WaitGroup`: add.

Parameters

w &mut WaitGroup
receiver &mut WaitGroup (exclusive borrow)
delta int
delta (int)

(&mut WaitGroup) done

XuAPI
pub fn (w &mut WaitGroup) done()

Purpose

Call `done` on `&mut WaitGroup`.

Parameters

w &mut WaitGroup
receiver &mut WaitGroup (exclusive borrow)

(&mut WaitGroup) wait

XuAPI
pub fn (w &mut WaitGroup) wait(n int)

Purpose

Call `wait` on `&mut WaitGroup`.

Parameters

w &mut WaitGroup
receiver &mut WaitGroup (exclusive borrow)
n int
count, length, or limit (int)

(&mut WaitGroup) wait_pending

XuAPI
pub fn (w &mut WaitGroup) wait_pending()

Purpose

Method on `&mut WaitGroup`: wait pending.

Parameters

w &mut WaitGroup
receiver &mut WaitGroup (exclusive borrow)

load_int

XuAPI
pub fn load_int(x &mut int) int

Purpose

===== sync/atomic ( sync/atomic, int-sized) ===== The runtime builtins are atomic_load / atomic_store / atomic_add atomic_cas — the `atomic_` prefix keeps them distinct from the wrapper names below (the same shadowing rule as the os package: a wrapper named `atomic_load` would shadow the builtin and self-recurse). Each builtin takes a mutable int location (`&mut int`; callers write `mut &x`). add returns the old value; cas returns a bool.

Parameters

x &mut int
value (exclusive borrow; type &mut int)

Returns

int — a value of this type

store_int

XuAPI
pub fn store_int(x &mut int, v int)

Purpose

Store int.

Parameters

x &mut int
value (exclusive borrow; type &mut int)
v int
value (int)

add_int

XuAPI
pub fn add_int(x &mut int, d int) int

Purpose

Add int.

Parameters

x &mut int
value (exclusive borrow; type &mut int)
d int
d (int)

Returns

int — a value of this type

compare_and_swap_int

XuAPI
pub fn compare_and_swap_int(x &mut int, old int, new int) bool

Purpose

Compare and swap int.

Parameters

x &mut int
value (exclusive borrow; type &mut int)
old int
old value / piece to replace (int)
new int
new value / replacement (int)

Returns

bool — true or false

struct Once

XuAPI
pub struct Once {
    pub state int
    pub mu Mutex
}

Purpose

===== Once ( sync.Once subset) ===== `do(f)` runs f at most once ( named fn values). `first_time` remains for call sites that prefer an explicit branch.

Parameters

state int
field (int)
mu Mutex
field (Mutex)

once

XuAPI
pub fn once() Once

Purpose

once; returns Once.

Parameters

none

Returns

Once — a value of this type

(&mut Once) first_time

XuAPI
pub fn (o &mut Once) first_time() bool

Purpose

Method on `&mut Once`: first time.

Parameters

o &mut Once
receiver &mut Once (exclusive borrow)

Returns

bool — true or false

(&mut Once) do

XuAPI
pub fn (o &mut Once) do(f fn())

Purpose

Call `do` on `&mut Once`.

Parameters

o &mut Once
receiver &mut Once (exclusive borrow)
f fn()
byte callback: argument is 0..255, return whether it matches

struct RWMutex

XuAPI
pub struct RWMutex {
    pub mu Mutex
    pub readers int
}

Purpose

===== RWMutex ( sync.RWMutex; reads do not run in parallel) ===== a single Mutex plus a reader count. Writers take the mutex; a reader takes it on entry (first-in) and releases it on exit (last-out), so reads serialize with each other and with writers — a documented divergence from parallel reads.

Parameters

mu Mutex
field (Mutex)
readers int
field (int)

rw_mutex

XuAPI
pub fn rw_mutex() RWMutex

Purpose

Rw mutex.

Parameters

none

Returns

RWMutex — a value of this type

(&mut RWMutex) read_lock

XuAPI
pub fn (m &mut RWMutex) read_lock()

Purpose

Method on `&mut RWMutex`: acquire a shared read lock.

Parameters

m &mut RWMutex
receiver &mut RWMutex (exclusive borrow)

(&mut RWMutex) read_unlock

XuAPI
pub fn (m &mut RWMutex) read_unlock()

Purpose

Method on `&mut RWMutex`: release a read lock.

Parameters

m &mut RWMutex
receiver &mut RWMutex (exclusive borrow)

(&mut RWMutex) write_lock

XuAPI
pub fn (m &mut RWMutex) write_lock()

Purpose

Method on `&mut RWMutex`: acquire an exclusive write lock.

Parameters

m &mut RWMutex
receiver &mut RWMutex (exclusive borrow)

(&mut RWMutex) write_unlock

XuAPI
pub fn (m &mut RWMutex) write_unlock()

Purpose

Method on `&mut RWMutex`: release a write lock.

Parameters

m &mut RWMutex
receiver &mut RWMutex (exclusive borrow)

struct Cond

XuAPI
pub struct Cond {
    pub q chan int
}

Purpose

===== Cond ( sync.Cond subset; ) ===== Locker is the Mutex passed to wait — no Locker interface. Callers must re-check the condition after wait returns (same contract as ). Notify is a shared channel so Cond values may be copied across `xu` (handles share the runtime object). No per-copy waiter counter.

Parameters

q chan int
field (channel; type chan int)

cond

XuAPI
pub fn cond() Cond

Purpose

cond; returns Cond.

Parameters

none

Returns

Cond — a value of this type

(&mut Cond) wait

XuAPI
pub fn (c &mut Cond) wait(m &mut Mutex)

Purpose

Call `wait` on `&mut Cond`.

Parameters

c &mut Cond
receiver &mut Cond (exclusive borrow)
m &mut Mutex
m (exclusive borrow; type &mut Mutex)

(&mut Cond) signal

XuAPI
pub fn (c &mut Cond) signal()

Purpose

Call `signal` on `&mut Cond`.

Parameters

c &mut Cond
receiver &mut Cond (exclusive borrow)

(&mut Cond) broadcast

XuAPI
pub fn (c &mut Cond) broadcast()

Purpose

Call `broadcast` on `&mut Cond`.

Parameters

c &mut Cond
receiver &mut Cond (exclusive borrow)