diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-09 18:32:36 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-09 18:32:36 +0800 |
commit | e3a08875f6435b1674e62bd1d923941ec2092b69 (patch) | |
tree | 144b3295768648a8eba1f9287a9dcacb20e3cac1 /miner/worker.go | |
parent | a7705fc2037836f037de5e5ea5aef8475424a1be (diff) | |
download | go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.tar go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.tar.gz go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.tar.bz2 go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.tar.lz go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.tar.xz go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.tar.zst go-tangerine-e3a08875f6435b1674e62bd1d923941ec2092b69.zip |
miner: start/stop mutex locked. Closes #887
Diffstat (limited to 'miner/worker.go')
-rw-r--r-- | miner/worker.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/miner/worker.go b/miner/worker.go index 7adf298ed..22493c235 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -125,6 +125,9 @@ func (self *worker) pendingBlock() *types.Block { } func (self *worker) start() { + self.mu.Lock() + defer self.mu.Unlock() + // spin up agents for _, agent := range self.agents { agent.Start() @@ -134,6 +137,9 @@ func (self *worker) start() { } func (self *worker) stop() { + self.mu.Lock() + defer self.mu.Unlock() + if atomic.LoadInt32(&self.mining) == 1 { // stop all agents for _, agent := range self.agents { @@ -146,6 +152,9 @@ func (self *worker) stop() { } func (self *worker) register(agent Agent) { + self.mu.Lock() + defer self.mu.Unlock() + self.agents = append(self.agents, agent) agent.SetReturnCh(self.recv) } |