DOC PREVIEW
Berkeley COMPSCI 162 - Lecture 4 Thread Dispatching

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS162 Operating Systems and Systems Programming Lecture 4 Thread DispatchingPrograms, Processes, ThreadsMultiple Processes Collaborate on a TaskShared Memory CommunicationInter-process Communication (IPC)Single and Multithreaded ProcessesExamples of multithreaded programsExamples of multithreaded programs (con’t)Thread StateExecution Stack ExampleSlide 11Slide 12Slide 13Slide 14ClassificationAdministriva: Project SignupGoals for TodaySingle-Threaded ExampleUse of ThreadsMemory Footprint of Two-Thread ExamplePer Thread StateLifecycle of a Thread (or Process)Ready Queue And Various I/O Device QueuesDispatch LoopRunning a threadInternal EventsStack for Yielding ThreadWhat do the stacks look like?Saving/Restoring state (often called “Context Switch)Switch DetailsSwitch Details (continued)What happens when thread blocks on I/O?External EventsExample: Network InterruptUse of Timer Interrupt to Return ControlChoosing a Thread to RunSummaryCS162Operating Systems andSystems ProgrammingLecture 4Thread DispatchingJanuary 28, 2010Ion Stoicahttp://inst.eecs.berkeley.edu/~cs162Lec 4.21/28/10 CS162 ©UCB Spring 2010Programs, Processes, Threads•Thread (lightweight process): unit of execution–A sequential execution stream of instructions–No protection between threads, other than CPU•Process (heavyweight process): unit of resource allocation, management–Protect memory, I/O •Why separate the concept of a thread from that of a process?–Discuss the “thread” part of a process (concurrency)–Separate from the “address space” (Protection)–Heavyweight Process  Process with one threadLec 4.31/28/10 CS162 ©UCB Spring 2010Multiple Processes Collaborate on a Task•High Creation/memory Overhead•(Relatively) High Context-Switch Overhead•Need Communication mechanism:–Separate Address Spaces Isolates Processes–Shared-Memory Mapping»Accomplished by mapping addresses to common DRAM»Read and Write through memory–Message Passing»send() and receive() messages»Works across networkProc 1 Proc 2 Proc 3Lec 4.41/28/10 CS162 ©UCB Spring 2010Shared Memory CommunicationProg 1VirtualAddressSpace 1Prog 2VirtualAddressSpace 2Data 2Stack 1Heap 1Code 1Stack 2Data 1Heap 2Code 2Shared•Communication occurs by “simply” reading/writing to shared address page–Really low overhead communication–Introduces complex synchronization problemsCodeDataHeapStackSharedCodeDataHeapStackSharedLec 4.51/28/10 CS162 ©UCB Spring 2010Inter-process Communication (IPC)•Mechanism for processes to communicate and to synchronize their actions•Message system – processes communicate with each other without resorting to shared variables•IPC facility provides two operations:–send(message) – message size fixed or variable –receive(message)•If P and Q wish to communicate, they need to:–establish a communication link between them–exchange messages via send/receive•Implementation of communication link–physical (e.g., shared memory, hardware bus, systcall/trap)–logical (e.g., logical properties)Lec 4.61/28/10 CS162 ©UCB Spring 2010Single and Multithreaded Processes•Threads encapsulate concurrency: “Active” component•Address spaces encapsulate protection: “Passive” part–Keeps buggy program from trashing the system•Why have multiple threads per address space?Lec 4.71/28/10 CS162 ©UCB Spring 2010Examples of multithreaded programs•Embedded systems –Elevators, Planes, Medical systems, Wristwatches–Single Program, concurrent operations•Most modern OS kernels–Internally concurrent because have to deal with concurrent requests by multiple users–But no protection needed within kernel•Database Servers–Access to shared data by many concurrent users–Also background utility processing must be doneLec 4.81/28/10 CS162 ©UCB Spring 2010Examples of multithreaded programs (con’t)•Network Servers–Concurrent requests from network–Again, single program, multiple concurrent operations–File server, Web server, and airline reservation systems•Parallel Programming (More than one physical CPU)–Split program into multiple threads for parallelism–This is called Multiprocessing•Some multiprocessors are actually uniprogrammed:–Multiple threads in one address space but one program at a timeLec 4.91/28/10 CS162 ©UCB Spring 2010Thread State•State shared by all threads in process/addr space–Contents of memory (global variables, heap)–I/O state (file system, network connections, etc)•State “private” to each thread –Kept in TCB  Thread Control Block–CPU registers (including, program counter)–Execution stack – what is this?•Execution Stack–Parameters (function arguments), return values–return PCs are kept while called procedures are executingLec 4.101/28/10 CS162 ©UCB Spring 2010Execution Stack Example•Stack holds function arguments, return address•Permits recursive execution•Crucial to modern languagesA(int tmp) { if (tmp<2) B(); printf(tmp);}B() { C();}C() { A(2);}A(1);exit;addrX:addrY:addrU:addrV:addrZ:............Lec 4.111/28/10 CS162 ©UCB Spring 2010Execution Stack Example•Stack holds function arguments, return address•Permits recursive execution•Crucial to modern languagesA(int tmp) { if (tmp<2) B(); printf(tmp);}B() { C();}C() { A(2);}A(1);exit;StackPointerStack GrowthA: tmp=1 ret=addrZaddrX:addrY:addrU:addrV:addrZ:............Lec 4.121/28/10 CS162 ©UCB Spring 2010Execution Stack Example•Stack holds function arguments, return address•Permits recursive execution•Crucial to modern languagesA(int tmp) { if (tmp<2) B(); printf(tmp);}B() { C();}C() { A(2);}A(1);exit;StackPointerStack GrowthA: tmp=1 ret=addrZB: ret=addrYaddrX:addrY:addrU:addrV:addrZ:............Lec 4.131/28/10 CS162 ©UCB Spring 2010Execution Stack Example•Stack holds function arguments, return address•Permits recursive execution•Crucial to modern languagesA(int tmp) { if (tmp<2) B(); printf(tmp);}B() { C();}C() { A(2);}A(1);exit;StackPointerStack GrowthA: tmp=1 ret=addrZB: ret=addrYC: ret=addrUaddrX:addrY:addrU:addrV:addrZ:............Lec 4.141/28/10 CS162 ©UCB Spring 2010Execution Stack Example•Stack holds function arguments, return address•Permits recursive execution•Crucial to modern languagesA(int tmp) { if (tmp<2) B(); printf(tmp);}B() { C();}C() { A(2);}A(1);exit;A: tmp=2 ret=addrVStackPointerStack GrowthA: tmp=1 ret=addrZB: ret=addrYC:


View Full Document

Berkeley COMPSCI 162 - Lecture 4 Thread Dispatching

Documents in this Course
Lecture 1

Lecture 1

12 pages

Nachos

Nachos

41 pages

Security

Security

39 pages

Load more
Download Lecture 4 Thread Dispatching
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 4 Thread Dispatching and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 4 Thread Dispatching 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?