program times out on go playground and runs but with race on mac running go1.16beta

110 views
Skip to first unread message

DrGo

unread,
Jan 20, 2021, 6:49:39 PM1/20/21
to golang-nuts
if I run this program in the playground, I get: timeout running program Program exited: status 1
https://play.golang.org/p/5cDYasXtl_n

If I run it on my macos Catalina machine with go 1.16 beta I get a data race warning

```
WARNING: DATA RACE
Read at 0x00c00011a2a0 by goroutine 10:
  main.New.func1()
     watcher/cmd/main.go:52 +0x29a

Previous write at 0x00c00011a2a0 by main goroutine:
  main.New()
     watcher/cmd/main.go:65 +0x36f
  main.main()
     watcher/cmd/main.go:91 +0x154

Goroutine 10 (running) created at:
  main.New()
     watcher/cmd/main.go:45 +0x304
  main.main()
     watcher/cmd/main.go:91 +0x154
```
I do not see any writing except in one spot in line 91.

What am I missing?

Thanks

Carla Pfaff

unread,
Jan 20, 2021, 7:02:29 PM1/20/21
to golang-nuts
    result <- Event{event, err}

reads the `err` variable in one goroutine, and

    err = watcher.Add(dir)

writes the same `err` variable in another goroutine.

DrGo

unread,
Jan 20, 2021, 8:33:34 PM1/20/21
to golang-nuts
Thanks a million 
Totally missed that first err was not limited to the scope of the case or the go routine.
Reply all
Reply to author
Forward
0 new messages