aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-09 18:32:36 +0800
committerobscuren <geffobscura@gmail.com>2015-05-09 18:32:36 +0800
commite3a08875f6435b1674e62bd1d923941ec2092b69 (patch)
tree144b3295768648a8eba1f9287a9dcacb20e3cac1
parenta7705fc2037836f037de5e5ea5aef8475424a1be (diff)
downloadgo-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
-rw-r--r--miner/worker.go9
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)
}