Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread fgergo
If you haven't studied concurrency before, I can't recommend any tutorials. To start to learn about concurrency, I'd first recommend _some_ reading and theoretical background. Concurrency is a complex concept. A "10x" multiplier estimation compared to e.g. structured programming is probably

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread mountainfpf
Is there a recommended tutorial? 在 2019年3月1日星期五 UTC+8下午12:21:58,Robert Engels写道: > > I think it would be helpful if you learned more about concurrent > programming. It is 10x harder, even with the simplifications that Go > offers. If you don’t understand the concepts you are going to struggle.

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread Robert Engels
I think it would be helpful if you learned more about concurrent programming. It is 10x harder, even with the simplifications that Go offers. If you don’t understand the concepts you are going to struggle. Start with some tutorials and work your way up. > On Feb 28, 2019, at 10:14 PM,

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread mountainfpf
This is the stack information printed when blocking, how to see which G blocking program? SIGABRT: abort PC=0x7fff9ceabbf2 m=0 sigcode=0 goroutine 0 [idle]: runtime.pthread_cond_wait(0x1967620, 0x19675e0, 0x7fff) /usr/local/go/src/runtime/sys_darwin.go:302 +0x51

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread howardcshaw
Sameer is correct, but to be clear - The *block* happens because the channel is empty, so the receive operation blocks forever. This happens in both of the cases you show. The *deadlock* happens because *all* goroutines are blocked and none can continue. So if you start some other goroutine

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread Sameer Ajmani
The deadlock happens because the channel is empty, so the receive operation blocks forever. The second version imports a package that may start new goroutines in its init functions. If so, those goroutines may not be deadlocked, but the main function is still blocked on the receive operation. It

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread mountainfpf
ok, thanks! 在 2019年2月28日星期四 UTC+8下午5:49:48,Jan Mercl写道: > > On Thu, Feb 28, 2019 at 10:20 AM > wrote: > > Please do not post colorized source code, particularly not using low > contrast, inverted color schemes. There are people not able to read it. > Some others may just ignore it or even

Re: [go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread Jan Mercl
On Thu, Feb 28, 2019 at 10:20 AM wrote: Please do not post colorized source code, particularly not using low contrast, inverted color schemes. There are people not able to read it. Some others may just ignore it or even consider it bad netiquette. Black on white is the most universally readable

[go-nuts] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread mountainfpf
dead lock: package main import ( "fmt" // _ "github.com/go-sql-driver/mysql" ) func main() { c1 := make(chan int, 10) fmt.Println(<-c1) } block: package main import ( "fmt" _ "github.com/go-sql-driver/mysql" ) func main() { c1 := make(chan int, 10)