On Sat, Dec 7, 2019 at 9:12 AM kr c <xnzm1...@gmail.com> wrote: > > https://play.golang.org/p/mqpT8XBbeiN > > Hi, Everyone! I'm newbie in go. Help needed. > As far as I learned, gorutines should pass "value" through channels. > There's more safe way to handle this kind of stuffs with using waitgroup, > context, channels....I thought, "sharing variable reference in gorutine" is > dangerous because of problems like transacion issue. > > But what if that value is just single error? Is it still unsafe or may cause > panic? > > "longTask" in examples is a task that I can garantee it will eventually end. > I know little about low level programming. So not sure if I can write this > kind of code.
That program is not safe. There is a race condition between writing to rerr in the goroutine and reading rerr in the deferred function. I would expect that the race detector would report a problem with this program (https://golang.org/doc/articles/race_detector.html). Use a channel. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVssRBNLWFni8Yn4W1GLwXWzbzqAqiiamAnvTEOaz-naw%40mail.gmail.com.