struct Mutex
pub struct Mutex {
pub tok chan int
}用途
公开结构体 `Mutex`。
参数
tokchan int- 字段(通道;类型 chan int)
API
#syncMutex / WaitGroup / Once / RWMutex / Cond 与原子 int。
struct Mutexpub struct Mutex {
pub tok chan int
}公开结构体 `Mutex`。
tok chan intstruct WaitGrouppub struct WaitGroup {
pub done chan int
pub pending int
}公开结构体 `WaitGroup`。
done chan intpending intmutexpub fn mutex() Mutexmutex,返回 Mutex。
无
Mutex — 该类型的值
(&mut Mutex) lockpub fn (m &mut Mutex) lock()`&mut Mutex` 上的方法:加锁,直到获得互斥。
m &mut Mutex(&mut Mutex) unlockpub fn (m &mut Mutex) unlock()`&mut Mutex` 上的方法:释放锁。
m &mut Mutexwait_grouppub fn wait_group() WaitGroup等待group。
无
WaitGroup — 该类型的值
(&mut WaitGroup) addpub fn (w &mut WaitGroup) add(delta int)`&mut WaitGroup` 上的方法:相加。
w &mut WaitGroupdelta int(&mut WaitGroup) donepub fn (w &mut WaitGroup) done()`&mut WaitGroup` 上的方法:完成一项。
w &mut WaitGroup(&mut WaitGroup) waitpub fn (w &mut WaitGroup) wait(n int)`&mut WaitGroup` 上的方法:等待。
w &mut WaitGroupn int(&mut WaitGroup) wait_pendingpub fn (w &mut WaitGroup) wait_pending()`&mut WaitGroup` 上的方法:等待pending。
w &mut WaitGroupload_intpub fn load_int(x &mut int) int读int。
x &mut intint — 该类型的值
store_intpub fn store_int(x &mut int, v int)写int。
x &mut intv intadd_intpub fn add_int(x &mut int, d int) int增加int。
x &mut intd intint — 该类型的值
compare_and_swap_intpub fn compare_and_swap_int(x &mut int, old int, new int) bool比较and交换int。
x &mut intold intnew intbool — 是否成立
struct Oncepub struct Once {
pub state int
pub mu Mutex
}公开结构体 `Once`。
state intmu Mutexoncepub fn once() Onceonce,返回 Once。
无
Once — 该类型的值
(&mut Once) first_timepub fn (o &mut Once) first_time() bool`&mut Once` 上的方法:首次time。
o &mut Oncebool — 是否成立
(&mut Once) dopub fn (o &mut Once) do(f fn())`&mut Once` 上的方法:执行一次。
o &mut Oncef fn()struct RWMutexpub struct RWMutex {
pub mu Mutex
pub readers int
}公开结构体 `RWMutex`。
mu Mutexreaders intrw_mutexpub fn rw_mutex() RWMutexrwmutex。
无
RWMutex — 该类型的值
(&mut RWMutex) read_lockpub fn (m &mut RWMutex) read_lock()`&mut RWMutex` 上的方法:获取共享读锁。
m &mut RWMutex(&mut RWMutex) read_unlockpub fn (m &mut RWMutex) read_unlock()`&mut RWMutex` 上的方法:释放读锁。
m &mut RWMutex(&mut RWMutex) write_lockpub fn (m &mut RWMutex) write_lock()`&mut RWMutex` 上的方法:获取独占写锁。
m &mut RWMutex(&mut RWMutex) write_unlockpub fn (m &mut RWMutex) write_unlock()`&mut RWMutex` 上的方法:释放写锁。
m &mut RWMutexstruct Condpub struct Cond {
pub q chan int
}公开结构体 `Cond`。
q chan intcondpub fn cond() Condcond,返回 Cond。
无
Cond — 该类型的值
(&mut Cond) waitpub fn (c &mut Cond) wait(m &mut Mutex)`&mut Cond` 上的方法:等待。
c &mut Condm &mut Mutex(&mut Cond) signalpub fn (c &mut Cond) signal()`&mut Cond` 上的方法:唤醒一个。
c &mut Cond(&mut Cond) broadcastpub fn (c &mut Cond) broadcast()`&mut Cond` 上的方法:唤醒全部。
c &mut Cond