Synchronizing threads
In an ideal world, threads would provide better application performance. But, at times, it isn't uncommon to notice that application performance degrades due to multiple threads. This performance issue may not be really tied to multiple threads; the real culprit could be the design. Too much use of synchronization leads to many thread-related issues that also lead to application performance degradation.
Lock-free thread designs not only avoid thread-related issues, but also improve the overall application performance. However, in a practical world, more than one thread may have to share one or more common resources. Hence, there arises a need to synchronize the critical section of code that accesses or modifies the shared resources. There are a variety of synchronization mechanisms that can be used in specific scenarios. In the following sections, we will explore them one by one with some interesting and practical use cases.