From 70f899352fbe56fa4355732a4bebb1ec4fff0d60 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 28 Jul 2025 15:48:35 -0300 Subject: [PATCH] fix: small fixes in csync --- internal/csync/doc.go | 3 +++ internal/csync/slices_test.go | 13 ++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 internal/csync/doc.go diff --git a/internal/csync/doc.go b/internal/csync/doc.go new file mode 100644 index 0000000000000000000000000000000000000000..b44fa2dac52172a8753e620e19f5c8d0a0481618 --- /dev/null +++ b/internal/csync/doc.go @@ -0,0 +1,3 @@ +// Package csync provides concurrent data structures for safe access in +// multi-threaded environments. +package csync diff --git a/internal/csync/slices_test.go b/internal/csync/slices_test.go index 414f6fe25047fa4bdbbaf205cde2c7568fcb4d28..8dafc1c1f4462dc45e2eb1fdeb71ffeacef260c1 100644 --- a/internal/csync/slices_test.go +++ b/internal/csync/slices_test.go @@ -260,22 +260,17 @@ func TestSlice(t *testing.T) { var wg sync.WaitGroup // Concurrent appends - for i := 0; i < numGoroutines; i++ { - wg.Add(1) + for i := range numGoroutines { + wg.Add(2) go func(start int) { defer wg.Done() - for j := 0; j < itemsPerGoroutine; j++ { + for j := range itemsPerGoroutine { s.Append(start*itemsPerGoroutine + j) } }(i) - } - - // Concurrent reads - for i := 0; i < numGoroutines; i++ { - wg.Add(1) go func() { defer wg.Done() - for j := 0; j < itemsPerGoroutine; j++ { + for range itemsPerGoroutine { s.Len() // Just read the length } }()