LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime_test | 5 package runtime_test |
6 | 6 |
7 import ( | 7 import ( |
8 "math" | 8 "math" |
9 "runtime" | 9 "runtime" |
10 "sync/atomic" | 10 "sync/atomic" |
| 11 "syscall" |
11 "testing" | 12 "testing" |
12 "time" | 13 "time" |
13 ) | 14 ) |
14 | 15 |
15 var stop = make(chan bool, 1) | 16 var stop = make(chan bool, 1) |
16 | 17 |
17 func perpetuumMobile() { | 18 func perpetuumMobile() { |
18 select { | 19 select { |
19 case <-stop: | 20 case <-stop: |
20 default: | 21 default: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 go func() { | 99 go func() { |
99 runtime.LockOSThread() | 100 runtime.LockOSThread() |
100 for i := 0; i < N; i++ { | 101 for i := 0; i < N; i++ { |
101 c <- true | 102 c <- true |
102 } | 103 } |
103 runtime.UnlockOSThread() | 104 runtime.UnlockOSThread() |
104 }() | 105 }() |
105 for i := 0; i < N; i++ { | 106 for i := 0; i < N; i++ { |
106 <-c | 107 <-c |
107 } | 108 } |
| 109 } |
| 110 |
| 111 func TestTimerFairness(t *testing.T) { |
| 112 done := make(chan bool) |
| 113 c := make(chan bool) |
| 114 for i := 0; i < 2; i++ { |
| 115 go func() { |
| 116 for { |
| 117 select { |
| 118 case c <- true: |
| 119 case <-done: |
| 120 return |
| 121 } |
| 122 } |
| 123 }() |
| 124 } |
| 125 |
| 126 timer := time.After(20 * time.Millisecond) |
| 127 for { |
| 128 select { |
| 129 case <-c: |
| 130 case <-timer: |
| 131 close(done) |
| 132 return |
| 133 } |
| 134 } |
| 135 } |
| 136 |
| 137 func TestTimerFairness2(t *testing.T) { |
| 138 done := make(chan bool) |
| 139 c := make(chan bool) |
| 140 for i := 0; i < 2; i++ { |
| 141 go func() { |
| 142 timer := time.After(20 * time.Millisecond) |
| 143 var buf [1]byte |
| 144 for { |
| 145 syscall.Read(0, buf[0:0]) |
| 146 select { |
| 147 case c <- true: |
| 148 case <-c: |
| 149 case <-timer: |
| 150 done <- true |
| 151 return |
| 152 } |
| 153 } |
| 154 }() |
| 155 } |
| 156 <-done |
| 157 <-done |
108 } | 158 } |
109 | 159 |
110 func stackGrowthRecursive(i int) { | 160 func stackGrowthRecursive(i int) { |
111 var pad [128]uint64 | 161 var pad [128]uint64 |
112 if i != 0 && pad[0] == 0 { | 162 if i != 0 && pad[0] == 0 { |
113 stackGrowthRecursive(i - 1) | 163 stackGrowthRecursive(i - 1) |
114 } | 164 } |
115 } | 165 } |
116 | 166 |
117 func TestSchedLocalQueue(t *testing.T) { | 167 func TestSchedLocalQueue(t *testing.T) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 for k := k0; k < k1; k++ { | 326 for k := k0; k < k1; k++ { |
277 C[i][j] += A[i][k] * B[k][j] | 327 C[i][j] += A[i][k] * B[k][j] |
278 } | 328 } |
279 } | 329 } |
280 } | 330 } |
281 } | 331 } |
282 if done != nil { | 332 if done != nil { |
283 done <- struct{}{} | 333 done <- struct{}{} |
284 } | 334 } |
285 } | 335 } |
LEFT | RIGHT |