1 / 19

Real-Time Systems Lecture 3

Real-Time Systems Lecture 3. Teachers: Olle Bowallius Phone: 790 44 42 Email: olleb@isk.kth.se Anders Västberg Phone: 790 44 55 Email: vastberg@kth.se. Concurrent Programming. Sequential Program Sequence of actions that produce a result Is called a process, task or thread

efuru
Download Presentation

Real-Time Systems Lecture 3

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. Real-Time SystemsLecture 3 Teachers: Olle Bowallius Phone: 790 44 42 Email: olleb@isk.kth.se Anders Västberg Phone: 790 44 55 Email: vastberg@kth.se

  2. Concurrent Programming • Sequential Program • Sequence of actions that produce a result • Is called a process, task or thread • Concurrent Program • Two or more processes that work together • Need synchronisation and communication

  3. Concurrent Programming • Constructs needed: • Notion of processes to express concurrent execution • Process synchronization • Communication between processes • Processes communicate via shared memory and/or by message passing

  4. Concurrent Programming The actual implementation (i.e. execution) of a collection of processes usually takes one of three forms. • Single processor • processes multiplex their executions on a single processor • Multiprocessor • processes multiplex their executions on a multiprocessor system where there is access to shared memory • Multicomputer (Distributed System) • processes multiplex their executions on several processors which do not share memory

  5. Concurrent Programming • Shared memory multiprocessor • Distributed memory machine [Andrews, 2000]

  6. Multiprogramming on a single Processor • Multiprogramming of four programs • Conceptual model of four independent, sequential processes • Only one program is active at once [Tanenbaum 2001]

  7. Process • A process is an executing a sequential program • Each process has its own virtual CPU • The context of each process. • Each record is called a Process Control Block or a Task Control Block • Contents: Contents in registers, pc, psw, sp, priority, id, other states.

  8. Process States Running Scheduler pick another process Process blocks for input Scheduler picks this process Blocked Ready Input becomes available

  9. Processes • Processes can be • Independent • Not synchronized or communicating • Cooperating • Synchronized and communicating • Competing • Peripheral devices, memory, and processor power • Must communicate to fairly share resources.

  10. Processer • Create processes: • Initialize the system • A process creates a child process • The user creates a new process • Run a batch job • The process is either initialized by passing parameters to it or by explicitly communicating to with the process after its created • Process termination • Completion • Suicide • Abortion by other process • Untrapped error condition • Never • When no longer needed

  11. Hierarchies of Processes • A process can create a child process • The child process can create new processes • Parent / Child • Parent responsible for the creation of Child process • Guardian / Dependent • The guardian process can not terminate until all dependent processes have terminated.

  12. Hierarchies of Processes • A process tree • A creates two child processes, B and C • B creates three child processes, D, E, and F

  13. Processes and Threads • All operating systems provide processes • Processes execute in their own virtual machine (VM) to avoid interference from other processes • Recent OSs provide mechanisms for creating threads within the same virtual machine; threads are sometimes provided transparently to the OS • Threads have unrestricted access to their VM • The programmer and the language must provide the protection from interference • Long debate over whether language should define concurrency or leave it up to the O.S. • Ada and Java provide concurrency • C, C++ do not

  14. Threads • Three processes with one thread each • One process with three threads

  15. Threads • Items shared by all threads in a process • Items private to each thread

  16. Variations in the Process Model • structure • static, dynamic • level • top level processes only (flat) • multilevel (nested) • initialization • with or without parameter passing • granularity • fine or coarse grain • termination • natural, suicide • abortion, untrapped error • never, when no longer needed • representation • coroutines, fork/join, cobegin, explicit process declarations

  17. Support for Concurrent Programming in OS Two main categories: • Pre-emptive multitaskingThe OS controls which process is executing. • Co-operative multitaskingThe current process decides if it shall stop executing.

  18. MicroC/OS-II int main(int argc, char *argv[]) { INT8U err; OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */ OSTaskCreate(AppStartTask, (void *) 0, (OS_STK*) &AppStartTaskStk[TASK_STK_SIZE-1], TASK_START_PRIO); OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */ }

  19. MicroC/OS-II void AppStartTask (void *p_arg) { p_arg = p_arg; while (TRUE) /* Task body, always written as an infinite loop. */ { OS_Printf("Delay 1 second and print\n"); OSTimeDlyHMSM(0, 0, 1, 0); /* OSTimeDly(1000) */ } }

More Related