MCPcopy Index your code
hub / github.com/goinaction/code / performWrite

Method performWrite

chapter7/patterns/semaphore/semaphore.go:200–216  ·  view source on GitHub ↗

performWrite performs the actual write work.

()

Source from the content-addressed store, hash-verified

198
199// performWrite performs the actual write work.
200func (rw *readerWriter) performWrite() {
201 // Wait a random number of milliseconds before we write again.
202 time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
203
204 log.Printf("%s\t: *****> Writing Pending\n", rw.name)
205
206 // Get a write lock for this critical section.
207 rw.WriteLock()
208
209 // Simulate some writing work.
210 log.Printf("%s\t: *****> Writing Start", rw.name)
211 time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
212 log.Printf("%s\t: *****> Writing Finish", rw.name)
213
214 // Release the write lock for this critical section.
215 rw.WriteUnlock()
216}
217
218// ReadLock guarantees only the maximum number of goroutines can read at a time.
219func (rw *readerWriter) ReadLock(reader int) {

Callers 1

writerMethod · 0.95

Calls 2

WriteLockMethod · 0.95
WriteUnlockMethod · 0.95

Tested by

no test coverage detected