Skip to content

Commit 46f3727

Browse files
authored
Merge pull request #85 from obalunenko/fix-race
fix(2016/day01): Data race issue
2 parents d382946 + eb7a7e6 commit 46f3727

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/puzzles/solutions/2016/day01/solution.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,14 @@ func (d direction) strikeTo(t turn) direction {
186186
}
187187

188188
type cab struct {
189+
mu *sync.Mutex
189190
curDir direction
190191
n navigator
191192
}
192193

193194
func newCab() cab {
194195
return cab{
196+
mu: &sync.Mutex{},
195197
curDir: northDirection,
196198
n: newNavigator(),
197199
}
@@ -204,6 +206,9 @@ const (
204206
)
205207

206208
func (c *cab) Move(t turn, steps int) error {
209+
c.mu.Lock()
210+
defer c.mu.Unlock()
211+
207212
c.curDir = c.curDir.strikeTo(t)
208213
if !c.curDir.isValid() {
209214
return errInvalidDirect

0 commit comments

Comments
 (0)