What is synchronization and why is it important? Describe synchronization in respect to multithreading.The access of sharing resources by multiple threads, in which only one thread can access a designated resource at a time, is known as synchronization.
Synchronization prevents data corruption which may lead to dirty reads and other significant errors.
With respect to multithreading, synchronization has the capability for controlling the access of multiple threads to shared resources. In non synchronization, there is every possibility for one thread to modify a shared variable, while another thread is in the process of updating the same shared data.What is synchronization and why is it important? Describe synchronization in respect to multithreading.Threads communicate by sharing access to fields and the objects.
However, due to threading there is a possibility of thread interference and memory inconsistency.
Synchronization is used to prevent this.
In synchronization, if an object is visible to more than a thread, all reads or writes to that object's variables are done through synchronized methods.
|