In: Computer Science
This week's problems are about another concurrent processing
problem: race conditions.
1. Find out what a race condition is, and explain in your own words
what goes wrong.
2. Which of the generic architectures considered in lectures is
most susceptible to race conditions. Explain your reasoning -- why
do you believe that your chosen architecture is most
susceptible?
3. Be creative, but realistic: Describe an example (of your own
creation) of a system that would be susceptible to a race
condition, and what might happen to cause the race condition in
your imagined system. Then explain what might be the effect of that
race condition in your particular system. The goal in this last
part is to imagine a real-world system and to describe it in a way
that the marker can understand as well as showing how it could be
affected by a race condition.
A race condition is a unprepared situation which occurs when two or more than two systems or threads tackle to perform two or more than two two operations at the same time or we can say that device or threads can fetch shared data and try to modifying or change it but according to the environment of device the operation perform its task correctly when its done in proper sequence.
For Example:
If a process calls a function that's proposed to increase a value (k) which is stored in a database. The function will fetch the current value from database (D) and store it in memory as a variable (E) then increment it (F) and finally write the updated value to database (G). This function's execution is a sequence of steps D-G.
Race condition will happen if process 1 calls this function and proceeds to step F. Meanwhile, it gets preempted by the operating system and another process 2 gets its chance to run. Process 2 calls the same function, completes all the steps D-G and returns. When process 1 resumes, it continues from step F using an old value (k), not process 2 result (k+1).
Race condition would not have happened if process 1 had completed all steps without preemption; or process 2 had been prevented from executing the function until process 1 had completed all steps.