Race Condition & Deadlock are not the same. Please refer following examples to understand the differences.
Race Condition: When two threads randomly tries to update a common variable.
Eg:
Eg:
Race Condition: When two threads randomly tries to update a common variable.
Eg:
Dead Lock: Two thread waiting without end[Expected result is 100 + 20 + 50 = 170]
- Var1 = 100
- Thread T1 & Thread T2 reads Var1 at same time
- But, T2 updates Var1 to 120 & exits
- Then, T1 updates Var1 to 150 & exits
- This leads to confused result for Var1
Eg:
http://support.microsoft.com/kb/317723
- Var1 is locked & used by Thread T1.
- Var2 is locked & used by Thread T2.
- T1 waits for Var1 to be released & T2 waits for Var2 to be released leading to dead lock.
No comments:
Post a Comment