E-Async Design Patterns

Double Checked Locking

This pattern is mostly used with singleton implementation. In this pattern Synch Variable is declared with Volatile keyword that force atomic read write.

For Dot.net world it works but for Java World there is no grantee to work. However Microsoft proposes static initialization i managed environment in compared to doubled checked locking because of overhead involved. Read More at MSDN ...

Condition Variable Pattern

It allows threads to efficiently synchronize their operations based on a complex condition by enabling threads to wait until a particular condition to occurs. Condition variables are user-mode objects that cannot be shared across processes.

Condition variables enable threads to atomically release a lock and enter the sleeping state. They can be used with critical sections or slim reader/writer (SRW) locks. Condition variables support operations that "wake one" or "wake all" waiting threads. After a thread is woken, it re-acquires the lock it released when the thread entered the sleeping state. Read More at MSDN ...

Reader Writer Pattern

Use this pattern when a resource (say variable) is be read and written both at the same . Popular example is connection manager in which multiple threads try to read (GetInstance) and Write (Create Instance) same object.I would suggest to use Reader Write Slim class from Threading library Read More ....

Producer consumer pattern

Producer Consumer is very famous problem from collage days. When I was in my college days I thought who the hell is going to use all this things but now I realize that how important they are. In Real world this problem occur when multiple thread try to add and remove the data from common pool like List or Buffer. There are two solutions to this problem ReaderWriterGate Class and Concurrent Collection or Snapshot method.

Reader Writer Gate Class

My recommendation is to use ReaderWriteGate class provided by Power Threading Library that provide non blocking implementation for this problem. Actually this class maintains reader and writer Queue to hold R/W request made and a thread pool to for execution. It has built in logic for non blocking synchronization of reader and writers.

Concurrent Collection (Snapshot Pattern)

This mechanism is use to access collections in concurrent way without blocking.Actually whenever any thread tried to access (Read) the collection it is given a snapshot of collection to access the data. Dot.Net support few classes like Concurrent Stacks,Queue, and Bag classes. Actually theses classes implement IProducerConsumerCollection.

Downside is that snapshot disconnected so use them only when if accuracy is not prime requirement because it does not provide real time access to data.