Synchronizing Threads

Learn to work with threads that handle shared resources.

We'll cover the following


Having multiple threads in an application lets us perform several tasks in parallel or ensure that the user interface is always responsive. When different threads work with some shared resources, be it a global variable or a file, we must begin to consider their intricacies.

Using shared resources

Consider the following example. The InsertNumber() method inserts some number in the middle of a text stored inside the text variable. For instance, if text holds the value, "Microsoft", calling InsertNumber(10) changes the value of text to "Micr10osoft". The method prints the new value of text and, after printing, it reverts it back to the original:

Get hands-on with 1200+ tech skills courses.