UCLDPER5MMVEP7V4UU7ZIXH7MYUZDW5MUDAJXX772Y3JDUAPOH3AC
7IEM2GFH5X7ZDBWA3LRKU3EU2XRPNGDEQSXXUBLV7T32WA4TI6NQC
func TestWaitGroup(t *testing.T) { t.Parallel() for _, tc := range TestCases { t.Run(tc.description, func(t *testing.T) { if tc.p != erastothenes.Nth("waitgroup", tc.n) { t.FailNow() } }) }}
func TestWaitGroup(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("waitgroup", tc.n) {
t.FailNow()
}
})
}func BenchmarkWaitGroup(b *testing.B) { for i := 0; i < b.N; i++ { erastothenes.Nth("waitgroup", benchNum) }}
func BenchmarkWaitGroup(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("waitgroup", benchNum)
"sync"
} } return sieve}// WaitGroup based parallel sieve.func WaitGroup(limit int) []bool { sieve := make([]bool, limit+1) wg := sync.WaitGroup{} wg.Add(1) go func() { // handle even numbers for i := 2 * 2; i <= limit; i += 2 { sieve[i] = true
return sieve
// WaitGroup based parallel sieve.
func WaitGroup(limit int) []bool {
sieve := make([]bool, limit+1)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
// handle even numbers
for i := 2 * 2; i <= limit; i += 2 {
sieve[i] = true
wg.Done() }() for p := 3; p*p <= limit; p += 2 { wg.Add(1) go func(p int) { for i := p * p; i <= limit; i += p { sieve[i] = true } wg.Done() }(p)
wg.Done()
}()
for p := 3; p*p <= limit; p += 2 {
go func(p int) {
for i := p * p; i <= limit; i += p {
}(p)
wg.Wait()
case "waitgroup": s = WaitGroup(primes.MAX)
case "waitgroup":
s = WaitGroup(primes.MAX)
3, true, }, { "third prime",
3,
true,
},
{
"third prime",
5, true, }, { "forth prime", 4, 7, true, }, { "fifth prime", 5, 11,
5,
"forth prime",
4,
7,
"fifth prime",
11,
true, }, { "seventh prime", 7, 17,
"seventh prime",
17,