performRead performs the actual reading work.
(reader int)
| 161 | |
| 162 | // performRead performs the actual reading work. |
| 163 | func (rw *readerWriter) performRead(reader int) { |
| 164 | // Get a read lock for this critical section. |
| 165 | rw.ReadLock(reader) |
| 166 | |
| 167 | // Safely increment the current reads counter |
| 168 | count := atomic.AddInt32(&rw.currentReads, 1) |
| 169 | |
| 170 | // Simulate some reading work |
| 171 | log.Printf("%s\t: [%d] Start\t- [%d] Reads\n", rw.name, reader, count) |
| 172 | time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond) |
| 173 | |
| 174 | // Safely decrement the current reads counter |
| 175 | count = atomic.AddInt32(&rw.currentReads, -1) |
| 176 | log.Printf("%s\t: [%d] Finish\t- [%d] Reads\n", rw.name, reader, count) |
| 177 | |
| 178 | // Release the read lock for this critical section. |
| 179 | rw.ReadUnlock(reader) |
| 180 | } |
| 181 | |
| 182 | // writer is a goroutine that listens on the shutdown channel and |
| 183 | // performs writes until the channel is signaled. |
no test coverage detected