1 / 17

Process Time-sharing system Critical section problem Semaphore Process communication

Lecture 12. Processes and Processes Synchronization . Process Time-sharing system Critical section problem Semaphore Process communication . Process . A process is a program in execution. A computer can run several programs simultaneously.

marion
Download Presentation

Process Time-sharing system Critical section problem Semaphore Process communication

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 12. Processes and Processes Synchronization • Process • Time-sharing system • Critical section problem • Semaphore • Process communication CS3369 Realtime Control Computer Software/WANG Lusheng

  2. Process • A process is a program in execution. • A computer can run several programs simultaneously. • A program can be executed several times by the same computer simultaneously. CS3369 Realtime Control Computer Software/WANG Lusheng

  3. Time-sharing System • Multiple jobs (processes) are executed by the CPU switching between them, but the switches occur so frequently that the users may interact with each program while it is running. • The switch among processes is done by OS. CS3369 Realtime Control Computer Software/WANG Lusheng

  4. Data communication in embedded systems. • Channels: directed transfer of information. • Pools: shared information. • Process Symbol: input output processing CS3369 Realtime Control Computer Software/WANG Lusheng

  5. Channels • A channel provides the medium for items of information to be passed between one process and another. • More than one item of information can pass through a channel at any one time and they are usually ordered according to the rule of FIFO (first-in-first-out). • Interrupt #0x09 stores keys typed by users in a buffer which is accessible by other interrupts. put ch._1 get g p CS3369 Realtime Control Computer Software/WANG Lusheng

  6. Pools • Items of information in a pool are available for reading and/or writing by a number of processes in the system. • Information does not flow within a pool. A pool acts as a repository of information. • Any item in a pool will be available to processes using the pool. CS3369 Realtime Control Computer Software/WANG Lusheng

  7. Pools are as important as processes: • processes are software models of the activities that an embedded system must perform; • pools form the software models of items in the system. These includes physical devices and mechanisms in the control system, and conceptual items such as logical files. • In many applications, the pool has information written into it endlessly. CS3369 Realtime Control Computer Software/WANG Lusheng

  8. Process Synchronization • Producer-consumer Problem • Producer keeps producing items and putting them in the buffer • Consumer keeps taking items away from the buffer. CS3369 Realtime Control Computer Software/WANG Lusheng

  9. Process Synchronization Producer’s code Repeat … produce an item in nextp … while counter = n do no-op; buffer[in]:=nextp; in:= in + 1 mod n; counter:= counter + 1; Until false; CS3369 Realtime Control Computer Software/WANG Lusheng

  10. Process Synchronization Consumer’s codes Repeat while counter =0 do no-op; nextc:= buffer[out]; out:=out + 1 mod n; counter:=counter –1; … consume the item in nextc … Untile false; CS3369 Realtime Control Computer Software/WANG Lusheng

  11. counter := counter +1 and counter: =counter -1 Each high level language statement corresponds to several lower level language statements. register1:=counter; register2:=counter; register1:=register1+1; register2=register2-1; counter:=register1; counter=register2 counter=counter+1; counter=counter-1; CS3369 Realtime Control Computer Software/WANG Lusheng

  12. The results could be wrong If counter =5 then after counter=counter+1; counter=counter-1; The result should be counter =5. However, it could be wrong: T0: producer register1:=counter; {register1=5} T1:producer register1:=register1+1; {register1=6} T2:consumer register2:=counter; {register2=5} T3:consumer register2=register2-1; {register2=4} T4:producer counter:=register1; {counter =6} T5:consumer counter=register2 {counter=4} CS3369 Realtime Control Computer Software/WANG Lusheng

  13. Cirtical section Why the result is wrong? Two processes access the same variable counter at about the same time. A critical section is a segment of codes that the process may be changing common resources, e.g., variables. CS3369 Realtime Control Computer Software/WANG Lusheng

  14. Semaphore A synchronization tool that can be used to solve some synchronization problem, e.g., the critical section problem. CS3369 Realtime Control Computer Software/WANG Lusheng

  15. Semaphore A semaphore S is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait and signal. Wait(s): while S<=0 do no-op; s=s-1; Signal(S): s=s+1; CS3369 Realtime Control Computer Software/WANG Lusheng

  16. Solve the Critical Section Problem Producer’s code Repeat … produce an item in nextp … while counter = n do no-op; wait(S); buffer[in]:=nextp; in:= in + 1 mod n; counter:= counter + 1; signal(S): Until false; CS3369 Realtime Control Computer Software/WANG Lusheng

  17. Solve the Critical Section Problem Consumer’s codes Repeat wait(S); while counter =0 do no-op; nextc:= buffer[out]; out:=out + 1 mod n; counter:=counter –1; signal(S); … consume the item in nextc … Untile false; CS3369 Realtime Control Computer Software/WANG Lusheng

More Related