Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can single processor environment prevent race condition?

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.

like image 619
Di Wang Avatar asked Jan 29 '23 11:01

Di Wang


1 Answers

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.

like image 188
Ameya Avatar answered Apr 27 '23 05:04

Ameya