Locking and the sync Package

This lesson gives a brief introduction on how Go tackles the problem of threading with the sync package.

We'll cover the following

A major problem

In more complex programs, different parts of the application may execute simultaneously (or concurrently as this is technically called), usually by executing each part of the program in a different thread of the operating system. When these different parts share and work with the same variables, problems are likely to occur. The order in which these shared variables are updated cannot be predicted, and hence, their values are also unpredictable! This is commonly called a race condition. The threads race for the updates of the variables. This is, of course, intolerable in a correct program, so how do we solve this issue?

Get hands-on with 1400+ tech skills courses.