Real Time Systems: Notes

Concurrency

 

Concurrent Execution - Multiprocessor

Concurrent Execution - Single Processor


What are the three scheduling policies shown?

Preemption

Need for Mutual Exclusion - Example of Race

procedure A is
begin ...
   M := M + 1; ...
end A;
procedure B is
begin ...
   M := M - 1; ...
end B;

No Interleaving: Task A First


Everything works fine.

No Interleaving: Task B First


Which task executes first does not matter.

Parallel Exclusion


With parallel or interleaved execution, what happens? We have a race between tasks A and B.

Even supposing the primitive memory fetch and store operations are atomic, the outcome depends on the particular interleaving of the operations.

If B Preempts A

If A Preempts B

Resource Example: Semaphores/Mutexes

This is the general idea. There are LOTS of variations on the details, to be covered later in this course.

Critical Section Protected by Lock/Unlock

procedure A is
begin ...
   Lock;
   M := M + 1;
   Unlock; ...
end A;
procedure B is
begin ...
   Lock;
   M := M - 1;
   Unlock; ...
end B;

With Locking/Unlocking

Other Examples of Non-Preemptable Resources

Counting Semaphores

Take a look at how locks are implemented in Linux, starting with the file spinlock.h, in /usr/src/linux-2.2.14/include/asm-i386.

For a more detailed commentary on the more subtle parts of the Linux spinlock implementation code click here.

Liu Notation and Terminology

Jobs

Tasks

© 1998, 2003 T. P. Baker. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means without written permission.
$Id: concurrency.html,v 1.1 2003/10/17 12:34:01 baker Exp baker $