MCPcopy
hub / github.com/mao888/golang-guide / writeWithLock

Function writeWithLock

golang/go-study/go语言基础/并发/并发安全和锁/读写互斥锁/rwMutex.go:22–28  ·  view source on GitHub ↗

writeWithLock 使用互斥锁的写操作

()

Source from the content-addressed store, hash-verified

20
21// writeWithLock 使用互斥锁的写操作
22func writeWithLock() {
23 mutex.Lock() // 加互斥锁
24 x += 1
25 time.Sleep(10 * time.Millisecond) // 假设读操作耗时10毫秒
26 mutex.Unlock() // 解互斥锁
27 wg.Done()
28}
29
30// readWithLock 使用互斥锁的读操作
31func readWithLock() {

Callers

nothing calls this directly

Calls 1

DoneMethod · 0.80

Tested by

no test coverage detected