First Problem: Race Conditions

First Problem: Race Conditions

 In this lecture, I am going to show you the most common multi-threading programming problem: a race condition. 

 A race condition happens when 2 or more threads are trying to access and modify the same variable. I will demonstrate a race condition with a very simple program, with 2 threads accessing a shared integer class member. 

 In the next section, I will show you a comprehensive solution for dealing with race conditions. For now, I will leave you with a tip on how to minimize the impact of race conditions in your code. 

Write Multithreaded C# Code

Buy nowLearn more

Introduction

  • Course Introduction
  • Introduction To Threading
  • Windows, OS/X or Linux?

Working With Threads

  • Section Introduction
  • How To Start A Thread
  • First Problem: Race Conditions
  • Passing In Data To A Thread
  • Second Problem: Waiting On A Thread
  • Joining And Suspending Threads
  • Interrupting And Aborting Threads
  • Section Recap
  • Quiz 1: Working with threads

Introducing Thread Locking

  • Section Introduction
  • When Should You Lock Threads?
  • The Lock Statement
  • Dealing With Deadlocks
  • Assignment: Have Dinner With The Philosophers
  • Using The Interlocked Class
  • Section Recap
  • Quiz 2: Thread Locking

How To Synchronize Threads

  • Section Introduction
  • Thread Synchronization With AutoResetEvents
  • How To Build A Producer/Consumer Queue
  • The ManualResetEvent Class
  • The CountdownEvent Class
  • Thread Rendezvous
  • Section Recap
  • Quiz 3: Thread Synchronization

Final Words

  • Course Recap