Skip to main content

Posts

Showing posts with the label double-check locking

Double check locking

Simple simulation of  muli-threading : few threads will read data from different sources and reduce them to get maximum from all the sources, An example of double check locking. lets make a  prototype of above problem. we will not go and solve it for generic case, we will simply create two thread thread1 and thread2;  this two threads will read data from two different sources and will will use a shared variable to get maximum of two data sets.  we will not go into details about what is singleton and double check locking, may be we see them in future post. in a sentence singleton is a design pattern that enable us to have only one     instantiation  of an object. that means we can't create  object of that class using new when and when ever we need to have object. So, our implementation logic goes as follows       1. start both the threads               find the max in each thread.      next update the shared variable; the class which holds the shared variable is fo