MCPcopy Create free account
hub / github.com/goinaction/code / ReadLock

Method ReadLock

chapter7/patterns/semaphore/semaphore.go:219–225  ·  view source on GitHub ↗

ReadLock guarantees only the maximum number of goroutines can read at a time.

(reader int)

Source from the content-addressed store, hash-verified

217
218// ReadLock guarantees only the maximum number of goroutines can read at a time.
219func (rw *readerWriter) ReadLock(reader int) {
220 // If a write is occurring, wait for it to complete.
221 rw.write.Wait()
222
223 // Acquire a buffer from the semaphore channel.
224 rw.readerControl.Acquire(1)
225}
226
227// ReadUnlock gives other goroutines waiting to read their opporunity.
228func (rw *readerWriter) ReadUnlock(reader int) {

Callers 1

performReadMethod · 0.95

Calls 1

AcquireMethod · 0.45

Tested by

no test coverage detected