Race condition is race between the users to access some resource.
Example:
Two thread with no synchronisation or no locking mechanism for variable access, can end up in race condition.
thread1:
if (x == 5) {
y = x * 2;
}
thread2:
x = 6;
Here problem occurs when check condition in thread1 is done, and then thread2 occurs which chnage x, then the result in y can be different(12) than expected(10).
To solve this kind of problem, Memory lock mechanism, Thread synchronisation, Interprocess ommunication etc. concepts are used.
Example:
Two thread with no synchronisation or no locking mechanism for variable access, can end up in race condition.
thread1:
if (x == 5) {
y = x * 2;
}
thread2:
x = 6;
Here problem occurs when check condition in thread1 is done, and then thread2 occurs which chnage x, then the result in y can be different(12) than expected(10).
To solve this kind of problem, Memory lock mechanism, Thread synchronisation, Interprocess ommunication etc. concepts are used.
No comments:
Post a Comment