Merge pull request #14 from alitto/bug/fix-waiting-count
Prevent WaitingTasks counter to wrap around and upgrade to Go v1.16
This commit is contained in:
@@ -11,6 +11,7 @@ go:
|
||||
- 1.13.x
|
||||
- 1.14.x
|
||||
- 1.15.x
|
||||
- 1.16.x
|
||||
|
||||
# Enable Go Modules
|
||||
env:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module github.com/alitto/pond/examples/dynamic_size
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/alitto/pond v1.5.0
|
||||
github.com/alitto/pond v1.5.1
|
||||
)
|
||||
|
||||
replace github.com/alitto/pond => ../../
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module github.com/alitto/pond/examples/fixed_size
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/alitto/pond v1.5.0
|
||||
github.com/alitto/pond v1.5.1
|
||||
)
|
||||
|
||||
replace github.com/alitto/pond => ../../
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module github.com/alitto/pond/examples/fixed_size
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/alitto/pond v1.5.0
|
||||
github.com/alitto/pond v1.5.1
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
)
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module github.com/alitto/pond/examples/task_group
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/alitto/pond v1.5.0
|
||||
github.com/alitto/pond v1.5.1
|
||||
)
|
||||
|
||||
replace github.com/alitto/pond => ../../
|
||||
|
||||
@@ -211,13 +211,15 @@ func (p *WorkerPool) submit(task func(), canWaitForIdleWorker bool) (submitted b
|
||||
return false
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if submitted {
|
||||
// Increment submitted task count
|
||||
atomic.AddUint64(&p.submittedTaskCount, 1)
|
||||
// Increment submitted and waiting task counters as soon as we receive a task
|
||||
atomic.AddUint64(&p.submittedTaskCount, 1)
|
||||
atomic.AddUint64(&p.waitingTaskCount, 1)
|
||||
|
||||
// Increment waiting task count
|
||||
atomic.AddUint64(&p.waitingTaskCount, 1)
|
||||
defer func() {
|
||||
if !submitted {
|
||||
// Task was not sumitted to the pool, decrement submitted and waiting task counters
|
||||
atomic.AddUint64(&p.submittedTaskCount, ^uint64(0))
|
||||
atomic.AddUint64(&p.waitingTaskCount, ^uint64(0))
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user