No output from goroutine

When your main() function ends, your program ends as well. It does not wait for other goroutines to finish. Quoting from the Go Language Specification: Program Execution: Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other … Read more

Append not thread-safe?

In Go no value is safe for concurrent read/write, slices (which are slice headers) are no exception. Yes, your code has data races. Run with the -race option to verify. Example: type myClass struct { AttributeName string } sourceSlice := make([]myClass, 100) destSlice := make([]myClass, 0) var wg sync.WaitGroup for _, myObject := range sourceSlice … Read more

Go project’s main goroutine sleep forever?

“Sleeping” You can use numerous constructs that block forever without “eating” up your CPU. For example a select without any case (and no default): select{} Or receiving from a channel where nobody sends anything: <-make(chan int) Or receiving from a nil channel also blocks forever: <-(chan int)(nil) Or sending on a nil channel also blocks … Read more

Break out of select loop?

The Go spec says: A “break” statement terminates execution of the innermost “for”, “switch”, or “select” statement within the same function. In your example you’re just breaking out of the select statement. If you replace break with a return statement you will see that it’s working.

Python-style generators in Go

Yes, increasing the buffer size might drastically increase the execution speed of your program, because it will reduce the number of context switches. Goroutines aren’t garbage-collected, but channels are. In your example, the fibonacci goroutine will run forever (waiting for another goroutine to read from the channel c), and the channel c will never be … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)