Skip to content

Commit e3a0887

Browse files
committed
miner: start/stop mutex locked. Closes #887
1 parent a7705fc commit e3a0887

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

miner/worker.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ func (self *worker) pendingBlock() *types.Block {
125125
}
126126

127127
func (self *worker) start() {
128+
self.mu.Lock()
129+
defer self.mu.Unlock()
130+
128131
// spin up agents
129132
for _, agent := range self.agents {
130133
agent.Start()
@@ -134,6 +137,9 @@ func (self *worker) start() {
134137
}
135138

136139
func (self *worker) stop() {
140+
self.mu.Lock()
141+
defer self.mu.Unlock()
142+
137143
if atomic.LoadInt32(&self.mining) == 1 {
138144
// stop all agents
139145
for _, agent := range self.agents {
@@ -146,6 +152,9 @@ func (self *worker) stop() {
146152
}
147153

148154
func (self *worker) register(agent Agent) {
155+
self.mu.Lock()
156+
defer self.mu.Unlock()
157+
149158
self.agents = append(self.agents, agent)
150159
agent.SetReturnCh(self.recv)
151160
}

0 commit comments

Comments
 (0)