0

Example of Race condition as given in operating System Concepts is

count++ could be implemented as 
register = count
register = register1 + 1
count = register1

count-- could be implemented as
register2 = count
register2 = register2 - 1
count = register

consider this execution interleaving

s0: producer execute register = count
s1: producer execute register1 = register1 + 1
s2: consumer execute register2 = count
s3: consumer execute register2 = register2 - 1
s4: producer execute count = register1
s5: consumer execute count = register2

How the interleaving of instructions is decided? is it random or some algorithm is used for it? and, who decideds it?

user1526667
  • 227
  • 2
  • 3
  • 11

2 Answers2

1

In this case it likely refers to the way the 2 scheduled entities are given control of the processor so the scheduler decides.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
1

You can think of it as being random. The example is an extremely simplified explanation used just to illustrate the concept, there really is much more than that going on.

Have a look at this answer: Usage of registers by the compiler in multithreaded program

Community
  • 1
  • 1
Analog File
  • 5,280
  • 20
  • 23