hstove / gender

Gender classification by first name in Go.
http://gender.hankstoever.com
101 stars 12 forks source link

learn.go - fatal error: concurrent map read and map write #1

Open tggo opened 7 years ago

tggo commented 7 years ago

I'm try run go run learn.go and get error fatal error: concurrent map read and map write if i change code in learn.go to like this:

 for i := start; i <= end; i++ {
    worker(classifier, i)
  }

and remove channels from func worker all working good

Тut with goroutine i catch error Сan you help me sove this problem. I'm just learning, and it is the second program on Go that I run. thanks

ps: go version go1.7.4 darwin/amd64

pierow2k commented 4 years ago

Realizing that this issue is several years old and that an answer is probably not relevant to tggo any longer…

If you continue trying to run learn.go it will eventually succeed.

while true; do go run learn.go >/dev/null 2>&1; if [ $? -eq 0 ]; then echo "Learn succeeded after ${i} attempts.  "; i=0; else ((i++)); fi; done

Learn succeeded after 2 attempts.
Learn succeeded after 23 attempts.
Learn succeeded after 23 attempts.
Learn succeeded after 25 attempts.
Learn succeeded after 23 attempts.
Learn succeeded after 18 attempts.
Learn succeeded after 6 attempts.
Learn succeeded after 19 attempts.
Learn succeeded after 43 attempts.
Learn succeeded after 1 attempts.
Learn succeeded after 10 attempts.
Learn succeeded after 37 attempts.
Learn succeeded after 7 attempts.
Learn succeeded after 42 attempts.
Learn succeeded after 33 attempts.
Learn succeeded after 1 attempts.
Learn succeeded after 24 attempts.
Learn succeeded after 16 attempts.
Learn succeeded after 16 attempts.
Learn succeeded after 4 attempts.