performWrite performs the actual write work.
()
| 198 | |
| 199 | // performWrite performs the actual write work. |
| 200 | func (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. |
| 219 | func (rw *readerWriter) ReadLock(reader int) { |
no test coverage detected