mirror of https://github.com/panjf2000/ants.git
Merge branch 'develop'
This commit is contained in:
commit
42609be153
11
README.md
11
README.md
|
@ -44,16 +44,16 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/panjf2000/ants"
|
"github.com/panjf2000/ants"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sum int32
|
var sum int32
|
||||||
|
|
||||||
func myFunc(i interface{}) error {
|
func myFunc(i interface{}) error {
|
||||||
n := i.(int)
|
n := i.(int32)
|
||||||
atomic.AddInt32(&sum, int32(n))
|
atomic.AddInt32(&sum, n)
|
||||||
fmt.Printf("run with %d\n", n)
|
fmt.Printf("run with %d\n", n)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,8 @@ func demoFunc() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
defer ants.Release()
|
||||||
|
|
||||||
runTimes := 1000
|
runTimes := 1000
|
||||||
|
|
||||||
// use the common pool
|
// use the common pool
|
||||||
|
@ -88,10 +90,11 @@ func main() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
defer p.Release()
|
||||||
// submit tasks
|
// submit tasks
|
||||||
for i := 0; i < runTimes; i++ {
|
for i := 0; i < runTimes; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
p.Serve(i)
|
p.Serve(int32(i))
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
fmt.Printf("running goroutines: %d\n", p.Running())
|
fmt.Printf("running goroutines: %d\n", p.Running())
|
||||||
|
|
11
README_ZH.md
11
README_ZH.md
|
@ -45,16 +45,16 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/panjf2000/ants"
|
"github.com/panjf2000/ants"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sum int32
|
var sum int32
|
||||||
|
|
||||||
func myFunc(i interface{}) error {
|
func myFunc(i interface{}) error {
|
||||||
n := i.(int)
|
n := i.(int32)
|
||||||
atomic.AddInt32(&sum, int32(n))
|
atomic.AddInt32(&sum, n)
|
||||||
fmt.Printf("run with %d\n", n)
|
fmt.Printf("run with %d\n", n)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,8 @@ func demoFunc() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
defer ants.Release()
|
||||||
|
|
||||||
runTimes := 1000
|
runTimes := 1000
|
||||||
|
|
||||||
// use the common pool
|
// use the common pool
|
||||||
|
@ -89,10 +91,11 @@ func main() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
defer p.Release()
|
||||||
// submit tasks
|
// submit tasks
|
||||||
for i := 0; i < runTimes; i++ {
|
for i := 0; i < runTimes; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
p.Serve(i)
|
p.Serve(int32(i))
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
fmt.Printf("running goroutines: %d\n", p.Running())
|
fmt.Printf("running goroutines: %d\n", p.Running())
|
||||||
|
|
|
@ -26,9 +26,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/panjf2000/ants"
|
"github.com/panjf2000/ants"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sum int32
|
var sum int32
|
||||||
|
|
Loading…
Reference in New Issue