Multithreading Best Practices

Multithreading requires careful programming. For most tasks, you can reduce complexity by queuing requests for execution by thread pool threads. This topic addresses more difficult situations, such as coordinating the work of multiple threads, or handling threads that block. Deadlocks and Race Conditions Multithreading solves problems with throughput and responsiveness, but in doing so it … Continue reading Multithreading Best Practices


Volatile and Thread.MemoryBarrier

Volatile variable and Thread.MemoryBarrier method use in condition when you want to access variable across threads without putting lock. You can read more about Volatile and Thread.MemoryBarrier on MSDN. Volatile keyword: Excerpts from MSDN The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to … Continue reading Volatile and Thread.MemoryBarrier

Multithreading Concept using .Net – Part III

Uses of Threads Foreground and Background Threads By default threads are foreground and if application is trying to close and if any foreground thread is running then application will close only after closing of all foreground threads, while background threads will automatically abort when all foreground threads will close. Therefore, you should use foreground threads … Continue reading Multithreading Concept using .Net – Part III

Multithreading Concept using .Net – Part II

Synchronization Concepts There are different strategies to make your thread safe or synchronize. Some of features are below: Basic Synchronization Thread .Sleep : Blocks execution for provided time period. Thread.Sleep(0) ; //will do context switch Thread.Sleep(100); // will block execution for 100 miliseconds Thread.Sleep(TimeSpan.FromMinutes(1)); // block for 1 minute Thread.Join : block thread execution until … Continue reading Multithreading Concept using .Net – Part II