on main help sign in
fix: small fixes in csync
70f8993Carlos Alexandro Becker
internal/csync/doc.gonew file+3
@@ -0,0 +1,3 @@
1+// Package csync provides concurrent data structures for safe access in
2+// multi-threaded environments.
3+package csync
internal/csync/slices_test.go+4−9
@@ -260,22 +260,17 @@ func TestSlice(t *testing.T) {
260 var wg sync.WaitGroup
260 var wg sync.WaitGroup
261
261
262 // Concurrent appends
262 // Concurrent appends
263− for i := 0; i < numGoroutines; i++ {
263+ for i := range numGoroutines {
264− wg.Add(1)
264+ wg.Add(2)
265 go func(start int) {
265 go func(start int) {
266 defer wg.Done()
266 defer wg.Done()
267− for j := 0; j < itemsPerGoroutine; j++ {
267+ for j := range itemsPerGoroutine {
268 s.Append(start*itemsPerGoroutine + j)
268 s.Append(start*itemsPerGoroutine + j)
269 }
269 }
270 }(i)
270 }(i)
271− }
272−
273− // Concurrent reads
274− for i := 0; i < numGoroutines; i++ {
275− wg.Add(1)
276 go func() {
271 go func() {
277 defer wg.Done()
272 defer wg.Done()
278− for j := 0; j < itemsPerGoroutine; j++ {
273+ for range itemsPerGoroutine {
279 s.Len() // Just read the length
274 s.Len() // Just read the length
280 }
275 }
281 }()
276 }()