Thank James! As I am very new to golang, I just write tons of micro applications to study its feature. :-)
On Monday, November 21, 2016 at 6:44:50 PM UTC-1, James Bardin wrote: > > > On Monday, November 21, 2016 at 2:23:37 PM UTC-5, zhaoguo wang wrote: >> >> Hi all, >> >> I wrote a simple application: the main function creates two goroutines, >> while these two goroutines use RPC to do simple communication >> continually. >> >> I found >> *if the main function falls into a busy loop after creating the two >> goroutines, * >> *the whole application will hang up after sending/receiving a couple >> number of RPCs* (~80 on my testbed). >> >> Can anyone illustrate why this happens? As each goroutine uses >> independent Linux threads, why one spins can affect others? >> >> > Threads are independent, but there's still a single runtime scheduler. > IIRC the busy loop is preventing the GC from being able to stop the world, > which in turn ends up blocking the scheduler. > > > >> I use *runtime.GOMAXPROCS(4)* to make sure each goroutine uses a >> Linux thread and the testbed is ubuntu 14.04 with 8 CPU cores. >> I use the go1.7.3 library which is compiled from the source code. I also >> attach the source code of the simple test, you should be >> able to run it with "go run test.go". >> > > > Just never use a busy loop. A busy loop is always an error, and there's no > reason to use 100% of a CPU just to block the main goroutine. You can use a > WaitGroup, channel receive, or even an empty select statement to block > efficiently if you want. > > > > -- 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.