summaryrefslogtreecommitdiff
path: root/static_pool.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-23 15:47:55 +0300
committerWolfy-J <[email protected]>2018-09-23 15:47:55 +0300
commit0d826d29d27cdc83766ceb60c33444603f67ade1 (patch)
tree0bb3af3528481af163d331104bd672bfc2794117 /static_pool.go
parentd208fa427bedeed367be4bab6d5285eb0a8984fb (diff)
task wait group protection added
Diffstat (limited to 'static_pool.go')
-rw-r--r--static_pool.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/static_pool.go b/static_pool.go
index b6e43ddc..432c9adc 100644
--- a/static_pool.go
+++ b/static_pool.go
@@ -26,6 +26,7 @@ type StaticPool struct {
factory Factory
// active task executions
+ tmu sync.Mutex
tasks sync.WaitGroup
// workers circular allocation buf
@@ -112,7 +113,10 @@ func (p *StaticPool) Workers() (workers []*Worker) {
// Exec one task with given payload and context, returns result or error.
func (p *StaticPool) Exec(rqs *Payload) (rsp *Payload, err error) {
+ p.tmu.Lock()
p.tasks.Add(1)
+ p.tmu.Unlock()
+
defer p.tasks.Done()
w, err := p.allocateWorker()
@@ -147,7 +151,10 @@ func (p *StaticPool) Exec(rqs *Payload) (rsp *Payload, err error) {
func (p *StaticPool) Destroy() {
atomic.AddInt32(&p.inDestroy, 1)
close(p.destroy)
+
+ p.tmu.Lock()
p.tasks.Wait()
+ p.tmu.Unlock()
var wg sync.WaitGroup
for _, w := range p.Workers() {