3
votes

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
single processor = single thread environment = No race condition. am I correct?Di Wang
I know single-thread environment prevent race condition, The problem is single processor = single thread environment? Correct?Di Wang
Go through the question which I've marked this as duplicate and you'll come to know whether you're correct!Am_I_Helpful

1 Answers

6
votes

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.