(gomaxprocs, numReaders int)
| 78 | } |
| 79 | |
| 80 | func doTestParallelReaders(gomaxprocs, numReaders int) { |
| 81 | runtime.GOMAXPROCS(gomaxprocs) |
| 82 | |
| 83 | var rwl *BoundedRWLock = NewBoundedRWLock(int(numReaders)) |
| 84 | clocked := make(chan bool) |
| 85 | cunlock := make(chan bool) |
| 86 | cdone := make(chan bool) |
| 87 | |
| 88 | reader := func() { |
| 89 | if err := rwl.RLock(100 * time.Millisecond); err != nil { |
| 90 | panic(fmt.Sprintf("contention??")) |
| 91 | } |
| 92 | |
| 93 | clocked <- true |
| 94 | <-cunlock |
| 95 | rwl.RUnlock() |
| 96 | cdone <- true |
| 97 | } |
| 98 | |
| 99 | // kick off parallel readers |
| 100 | for i := 0; i < numReaders; i++ { |
| 101 | go reader() |
| 102 | } |
| 103 | |
| 104 | // wait for them to all acquire the rlock |
| 105 | for i := 0; i < numReaders; i++ { |
| 106 | <-clocked |
| 107 | } |
| 108 | |
| 109 | // ask them to unlock |
| 110 | for i := 0; i < numReaders; i++ { |
| 111 | cunlock <- true |
| 112 | } |
| 113 | |
| 114 | // wait for them to unlock |
| 115 | for i := 0; i < numReaders; i++ { |
| 116 | <-cdone |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func (suite *BoundedRWLockSuite) TestParallelReaders(t *C) { |
| 121 | // restore the original value after we are done with the test |
no test coverage detected