There have been many articles providing technical analysis and explanation. I would like to write a more easy-understanding article from a perspective of people with non-technical backgrounds
I find that I was just using Golang's syntax to write Java after I reviewed the Golang code I wrote years ago, I was a newbie in Golang then. Especially in writing concurrency programs, the design ideas are totally different between Golang and Java: we are used to designing concurrency with the idea "thread-safe" in Java, but we would use the idea "channel" more in Golang.
One of the most important features of Golang is its ability to handle high concurrency. And goroutine is the foundation to support high concurrency. This article will briefly explain how Java’s thread model and Golang’s goroutine work in OS. And I believe you will be impressive in the principle behind goroutine. Let’s go!
When writing concurrency code, we often use mechanisms like Lock or Synchronized to protect share resources (sometimes it’s a piece of code). What if we merely want to protect one variable but not a whole code? It’s too expensive to use Lock or Synchronized to protect just one variable.