Introduction to Synchronization
Learn how the activities of the threads can be synchronized in different ways.
In a multithreaded application, we might need to coordinate (synchronize) the activities of the threads running in it.
The need to synchronize the activities of threads can arise in two situations:
- When data or other resources have to be shared amongst threads.
- When we need to carry out communication between threads.
Examples of sharing resources
Example 1
Suppose a function has a statement n = n + 1
. Here, the value of n
is read, 1
is added to it, and the result is ...