In: Computer Science
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.
Race condition is a situation in which concurrently executing processes accessing the same shared data item may affect the consistency of the data item.Outcome of the execution depends the particular order in which the statements are executed. We can take an example of a food recipe that needs two cooks to prepare and the time to make the cake is two hours. The cake needs to be placed in a pan to get baked in an oven and a flavoured syrup has to be poured over the cake at the beginning and flip over to let it cook on the other side of the cake , after an hour the dish needs to be flipped over again and the same flavoured syrup is added on the same side , but this time no flipping is is done and kept as it is to cook for an hour again. Total time will be then 2 hours. It has been decided that two cooks will be doing the task of adding the flavoured syrup . Here the first cook does his task properly and flips the dish , but unfortunately the second Cook was not informed about it so he again pours the syrup and turns the cake again and let it cook.
Here the problem of race condition has occurred, as the same task has been done in the same time, i.e, at the beginning. Thus the recipe and the flavour has been added on both the sides of the cake.whereas it should have been added twice on the same side of the cake after an interval of an hour.
The effect in the case would be that the cake will not have it's expected taste and it would be undercooked as the flavour went on both the sides or it may have a odd taste as well.
To avoid the race condition the first cook after completing his task should have informed the second Cook that he have already done his task and next time the second Cook has to add the syrup. Here both the cook has shared the same process at the same time, here the process is the task of adding syrup.