can single processor environment prevent race condition?

瘦欲@ 提交于 2019-12-24 00:49:45

问题


When multiple processors are working, the processes are working concurrently. Race condition happens when multiple threads accessing some common data area, one may overwrite the other value.

So, if it is a single processor and single core environment, can it prevent the race condition from happening?

Help me clarify this confusion, Thank you.


回答1:


A race condition could happen in Single processor environment. As per Wiki Race Condition occurs when output is dependent on the sequence or timing of other uncontrollable events

Single processor environment could support multiple threads of the same process of different process that might be waiting for another thread to yield on a resource. Deadlocks can happen in single processor environments too.

Scenario:

  • T1: Wants add an employee record to file "employee.txt"
  • T2: Wants to compute average salary for "legal dept"
  • T3: Wants to remove an employee who left
  • T4: Wants to list number of employees working in each dept

If all the above threads are waiting at time=0 and submitted to single processor, it would decide which thread goes first, second and so on. The order in which the Threads are prioritised and yielded differs on different platform, scenarios etc. Thus T2 and T4 might not give consistent result.



来源:https://stackoverflow.com/questions/46556478/can-single-processor-environment-prevent-race-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!