Well, concurency is an advanced concept, do not start learning Go with this. Try some simple things to understand the concepts. Related to your problem concurency have some rules. Being something like a little process in your program is scheduled by the runtime and often you can see that the goroutine finish, the next instruction is executed and after that the goroutine do something. That’s normal in concurency and you will see many things executed in unexpected order. To do things in order you must synchronize the goroutines by hand.
I’m not just starting learning concurrency, but I’m not an expert either. I’ve dealt with multi-theaded programs in the past and written some but it’s been years. That’s why I was asking if “go” was similar to to “fork” in C.
I also thought, since it’s a learning site, you might want to explain that results can vary from the stated.
you might want to explain that results can vary from the stated
In concurency the routines start at various moments in time and take a time to initialize and do some action. In this time the program continue and some time later you could see the result of the goroutine. There is no default or guaranteed order in concurency, so if you launch a few goroutines in some order the results may not respect that order. Also concurency is not parralelism.
I also had prior experience with multiprocessing with the fork() system call, and multi-threading with POSIX threads. Those helped me understand many of the fundamental concepts of concurrency. So I think you have a very good place to start from.
Concurrency in Go is something more than those, so you will need to learn about how concurrency is implemented in Go, along with channels, which are used for inter-goroutine communication, including data transfer and signaling.
There are many good learning resources, including chapters of various books on Go, a whole book, Concurrency in Go, lessons in video courses. (Ultimate Go by @William Kennedy is excellent IMO), and also videos on YouTube. After you understand the fundamentals, try searching for videos on Go concurrency patterns.
Thank You guys. I’ll work on it. I was trying to get the basics by going through gobyexample. I’ll be trying to write some code after that. I would love to take time to learn slowly but I’ll probably have to fumble through some. Most of the stuff I’ll be trying to begin with won’t be anything complex.