Presentation is loading. Please wait.

Presentation is loading. Please wait.

Real Time System KUKUM Last lecture- Summary Definition of Real Time System Types of RTS Slow/Fast RTS What is OS & its functionality, Kernel ?, RTOS how.

Similar presentations


Presentation on theme: "Real Time System KUKUM Last lecture- Summary Definition of Real Time System Types of RTS Slow/Fast RTS What is OS & its functionality, Kernel ?, RTOS how."— Presentation transcript:

1 Real Time System KUKUM Last lecture- Summary Definition of Real Time System Types of RTS Slow/Fast RTS What is OS & its functionality, Kernel ?, RTOS how is it different from OS: –Multitasking –pre-emptable (priority) –Process synch –Interrupt latencyPredictable –Mask interrupt –Sys call

2 Real Time System KUKUM Concurrency and Concurrent Programming

3 Real Time System KUKUM Objectives Able to explain the: –Concept of concurrency –Interaction between concurrent processes –Identify pathological cases ( to be avoided) Able to design and implement concurrent software

4 Real Time System KUKUM Lecture contents Concept of concurrency Abstraction of concurrent programming Correctness of concurrent program Writing concurrent program

5 Real Time System KUKUM Concept of Concurrency In programming There are two fundamental types of programming: ·Sequential ·parallel

6 Real Time System KUKUM Sequential Programming In SP, processes are executed in order, one followed by another Analogy: shopping in a supermarket Buy meat, then buy vegetables, then buy drinks, then pay at the counter For a given input, the computer always executes the same sequence instructions. Program is easier to write (logical) Most probably not suitable to solve real-time problems

7 Real Time System KUKUM Example of SP function add_two_list( int1, int2: integer) begin sum:= 0 sum = int1 sum = sum + int2 return sum end add_two_list A single sequence of control

8 Real Time System KUKUM Concurrent programming (CP) In CP, processes are executed in parallel Analogy: shopping in supermarket Mother buys meat, father buys veg., son buys drinks ( at once), then all meet by the pay counter Harder to model and to program Each time the sequence of execution of instructions is non deterministic Appropriate for time critical/ real time problems

9 Real Time System KUKUM Conceptually… We study it by looking at the: –Examples, abstraction and model of CP –Classical problems which illustrate the concepts Programming-wise? –Some languages have no support for concurrency, so we need other means to achive it, eg. OS support (UNIX system calls) –Using ‘task’ in ADA or ‘thread’ in C++

10 Real Time System KUKUM Definition – concurrent programming “Concurrent programming” is the term given to programming notations and techniques for expressing potential parallellism and for solving the related sycnhronization and communication problems.” Eg: x: y:z:= 60:15:120; Where x,y, and z are all assigned their respective values concurrently( undeterministic which assignment is done first).

11 Real Time System KUKUM Definition – Program & Process (Ben-Ari’s definition) A concurrent program is a set of “ sequential programs” which are executed in abstract parallelism. Each sequential program is called a process, and the whole set of process is called the concurrent program.

12 Real Time System KUKUM Examples of concurrency overlapped I/O and computation Main I/O Start I/O Wait for I/O End of I/O

13 Real Time System KUKUM …/ examples of concurrency Multi programming A concurrent execution of several independent programs Eg: running excel, word, and email concurrently on a PC where the excel is calculating something, a file is being edited and email is being constantly checked for mail arival.

14 Real Time System KUKUM …/ examples of concurrency Multi tasking Solving a problem by decomposing it into several sub-tasks. Examples Sort algorithms Summation of huge set of number Computing binomial coefficient

15 Real Time System KUKUM Why do we need concurrency –Improve speed of execution o processes –Different peripherals have different speed –True to reality- real time behavior of problems in everyday life

16 Real Time System KUKUM Types of concurrency Semi-concurrency –Two or more processes will run on the same processor, one at a time, using and releasing the processor, managed by the OS. True concurrency –Many processes run on several processors at the same time (transputer environment)

17 Real Time System KUKUM Try this out This exercise is intended to get a feeling of the problem inherent in CP. –Assume you can write an SP program which produces an endless series of the following sentence: “A person with one watch knows what time it is; a person with two watches is never sure!” –Now write a pseudo-CP program to do the above using two processes, where P1 prints out the first two lines, and P2 the rest. What is the output look like?

18 Real Time System KUKUM Abstraction of concurrent programming Timing Interleaving Atomicity of operation

19 Real Time System KUKUM Abstraction An abstraction is an idealized/simplified model of a phenomenon. The model can then be used to study a more complex system which uses the abstraction. Example: –Human body: organs and the various systems –Computer: OS-> instructions -> electronics –Complex software system: components and their interconnections

20 Real Time System KUKUM …/Abstraction To understand CP, we need a number of abstractions about processes. –Interleaving –Timing –Atomicity of operations in a process We want to use these to identify the problems and also prove the correctness of a CP

21 Real Time System KUKUM Interleaving For analysis of CP we say that the execution sequences of concurrent processes are interleaved and each process has its own processor time. Between interleaving processes there can be contention and communication. –Contention: processes compete for resources –Communication: processes may need to exchange information In fact there are various scheduling mechanism used to manage the interleaving order of processes. To show that a CP is incorrect we must be able to show that there exist at least one bad interleaving sequence which does not meet the system specification.

22 Real Time System KUKUM …/ Interleaving A concurrent program must be correct under all kinds of interleaving. Furthermore, fairness must be guaranteed, ie. The scheduler manages is such a way that eventually every instruction in each process must be executed. If it can be shown that a process is deferred forever in its execution under a sequence of interleaving then the process is said to be “starved”.

23 Real Time System KUKUM Timing The interleaving abstraction also makes no assumption about absolute timing between the execution of processes. –If process-P must finish before process-Q is started, it is irrelevant if it finishes 1 second or 1 hour before. This is a weak specification and can be misleading. But it is a necessary abstraction because… –Execution sequence are more appropriate in proving correctness rather than absolute timing –Systems are always upgraded with newer and faster hardware and if correctness depends on absolute timing we always need to recheck its correctness every time a new device with a new timing is installed. Of course in a real system, the specification must include the absolute real time requirement, otherwise the system may be theoretically correct but still does not meet its requirement.

24 Real Time System KUKUM Atomic Instructions Interleaving of processes are done on sequences of atomic (undivisible) instructions. The correctness of a CP depends on the level of atomicity used by the computer when processes interleaved. For example, consider the following two processes which execute in parallel but at different atomic levels: Instruction level Register level

25 Real Time System KUKUM …/ Atomic instructions N: Integer := 0; -- a global var process P is--specification of process P Begin N:= N+1 End P; process Q is--specification of process Q Begin N:= N+1 End Q;

26 Real Time System KUKUM Instruction level Process Instruction Value of N (Initially)0 PINC N1 QINC N2 Process Instruction Value of N (Initially)0 QINC N1 pINC N2 Result is correct, since there are 2 processes each incrementing N by 1, so final value of N=2, whichever process executes first.

27 Real Time System KUKUM Reqister level At the register level instruction, the statement N:=N+1 is equivalent to the series of instructions as follow: LOAD Reg, N ADDReg, #1 STOREN, Reg Where LOAD, ADD and store are atomic instructions and N is the global

28 Real Time System KUKUM Register level Process Instruction N Reg(1) Reg(2) (Initially)0-- PLOADReg, N00- QLOADReg, N000 PADDReg, #1010 QADDReg, #1011 PSTOREReg, N111 QSTOREReg, N111 Result is not correct, based on the specification in the requirement

29 Real Time System KUKUM By comparison It shows that a different level of atomicity leads to a wrong result when processed are interleaved. Obviously, there are tradeoffs between the level of atomicity vs correctness and between the level of atomicity vs. difficulty in implementation. Generally, prefer a higher level of atomicity, although need to consider speed.

30 Real Time System KUKUM Concurrency Implementation C++: thread OS support Example Defn: Types Multi tasking Multi programming tech to  parallelism, Solve synch & comm True Conc. Semi Conc. Abstraction Atomicity Interleaving Timing


Download ppt "Real Time System KUKUM Last lecture- Summary Definition of Real Time System Types of RTS Slow/Fast RTS What is OS & its functionality, Kernel ?, RTOS how."

Similar presentations


Ads by Google