KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The definition of a race condition: A race condition or race hazard is a flaw in a system or process whereby the output or result of the process is unexpectedly and critically dependent on the sequence or timing of other events. Consider the following pseudocode: Global variable i initialized to 6; Thread 1: acquire(lock l) increment global variable i, i.e. i++; Thread 2: acquire(lock l) double the value of global var i, i.e.: i*=2; If T1 acquires the lock l first and T2 second the value of i will be 14. On the other hand, if T2 acquires the lock l first and T1 second the value of i will be 13. So, is this a race condition or not ? UPDATE: after a number of comments and answers, the opinions are still divergent. My opinion is in the "YES, this is a race condition" category. Actually I gave this example as a race condition situation, on a different question. At the same time, I also read some interesting comments in the "NO, this isn't a race condition" category. I think I will settle and conclude that this is or isn't a race condition depending on the perspective/level from which one looks at the problem. However, I'm still waiting for interesting answers/comments.
Tags (comma-separated)
Save Edits
Cancel