It clearly shows a 'chan receive' item in that trace, which is from the <-variable part. That is the blocker.
STW pauses are rarely more than a few seconds long, and you would have to have allocated massive amounts of memory, then stopped using it, to cause one. Finding good examples of working channel/goroutine usage is not that hard. https://github.com/parallelcointeam/pod/blob/master/pkg/util/clog/clog.go is a logging library I wrote that uses channels to separate the main server's runtime goroutines from the overhead of stopping their work to log (it also has the possibility of using closures to further reduce the initial call cost when the log level is not active, when preparing the data for more detailed high log levels (debug and especially trace). I wrote that mainly by reading the go tour, and a few things, maybe a tutorial on Medium. I am not sure why I am the first to use channels for a logger, but I am fairly sure I am. I will warn you that it can be very difficult to debug goroutines and channels, as correct implementation depends on you matching routines that fill the channel with routines that empty it. I don't know if there is any helper tools or linters that help you spot unmatched ins and outs. Go's implementation of concurrency is probably one of the simplest there is, as well as the most light weight. This one feature is probably the thing that makes go the best choice for concurrent programming, period. Even just yesterday someone posted results of implementing such in Java as well as Go, and the Go was better on memory and latency, though the throughput of each thread was lower overall, Go can run hundreds of them with far less overhead cost per thread, and channels allow synchronisation without explicit locking, and the inbuilt lock system of channels is very low cost also, lower than waitgroups and sync mutexes. Good luck with it, but seriously, you can't have been searching long if you didn't know you have to spawn at least one goroutine to use a channel. On Friday, 1 March 2019 04:13:11 UTC+1, mount...@gmail.com wrote: > > First of all, I am very grateful for your reply. I still want to know if > it has anything to do with STW? > > 在 2019年3月1日星期五 UTC+8上午3:55:57,Louki Sumirniy写道: >> >> Channels require goroutines. `<-variable` blocks the goroutine it is in >> and waits for another goroutine to do the opposite, being `channel <- >> value` You can't use channels without goroutines, and really, the main >> purpose for goroutines is exactly about moving things through channels. >> >> Goroutines probably are the most confusing and error prone part of Go, as >> it can be very hard to see who is loading the channel and who is not, and >> if they are in the same goroutine it won't work, as one part of it waits >> for the other part that will never start running, because it already is, >> and is blocked. >> > -- 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.