Re: [go-nuts] is this code thread safety?
What Jan said. I had started my own post before I realize other sane people checked in about the absurd colors. On Thursday, November 2, 2017 at 3:13:07 AM UTC-7, Jan Mercl wrote: > > On Thu, Nov 2, 2017 at 6:54 AM sheepbao> wrote: > > > the close function is thread safety? how about call `closed` at the same > time. > > I don't know, but you might want to reconsider posting text with contrast > going in some places below 10% (guestimated), to possibly get answers from > people which refuse to read what's not really readable. > > Black on white is the best. > > -- > > -j > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] is this code thread safety?
In general you can use the race detector to help answer this sort of question, although it does not detect all races. Unfortunately, it doesn't detect this one. (I've filed https://golang.org/issue/22569, because I think it should.) On Friday, November 3, 2017 at 4:08:19 AM UTC-4, sheepbao wrote: > > Thanks, I got it. > > On Friday, November 3, 2017 at 11:26:31 AM UTC+8, Jesse McNelis wrote: >> >> On Thu, Nov 2, 2017 at 4:54 PM, sheepbaowrote: >> > >> > the close function is thread safety? how about call `closed` at the >> same >> > time. >> >> It's not safe. Multiple goroutines can enter the 'default' case in >> that select and close() the channel multiple times. >> >> "Sending to or closing a closed channel causes a run-time panic." >> https://golang.org/ref/spec#Close >> > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] is this code thread safety?
Thanks, I got it. On Friday, November 3, 2017 at 11:26:31 AM UTC+8, Jesse McNelis wrote: > > On Thu, Nov 2, 2017 at 4:54 PM, sheepbao> wrote: > > > > the close function is thread safety? how about call `closed` at the same > > time. > > It's not safe. Multiple goroutines can enter the 'default' case in > that select and close() the channel multiple times. > > "Sending to or closing a closed channel causes a run-time panic." > https://golang.org/ref/spec#Close > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] is this code thread safety?
On Thu, Nov 2, 2017 at 4:54 PM, sheepbaowrote: > > the close function is thread safety? how about call `closed` at the same > time. It's not safe. Multiple goroutines can enter the 'default' case in that select and close() the channel multiple times. "Sending to or closing a closed channel causes a run-time panic." https://golang.org/ref/spec#Close -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] is this code thread safety?
package main import "time" import "fmt" import "sync/atomic" func main() { die := make(chan struct{}) i := int32(0) closed := func() { select { case <-die: atomic.AddInt32(, 1) default: close(die) fmt.Println("closed") } } N := 10 for i := 0; i < N; i++ { go closed() } time.Sleep(10 * time.Second) fmt.Println(atomic.LoadInt32()) } the close function is thread safety? how about call `closed` at the same time. -- 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. For more options, visit https://groups.google.com/d/optout.