Unformatted text preview:

Slide 1AnnouncementsProgram #1: Threads - addendaSlide 4Slide 5What is a Process?How is a Process Structured in Memory?Multiple ProcessesSlide 9Context SwitchingThreadsSlide 12Slide 13Processes &ThreadsThread-Safe/Reentrant CodeUser-Space and Kernel ThreadsModel of Process ExecutionThe SchedulerInvoking the SchedulerVoluntary CPU SharingMore on YieldVoluntary SharingInvoluntary CPU SharingInvoluntary CPU Sharing (cont)Contemporary SchedulingChoosing a Process to RunPolicy ConsiderationsOptimal SchedulingHowever ...Slide 30Talking About Scheduling ...Slide 32Estimating CPU UtilizationSlide 34Nonpreemptive SchedulersSlide 36Slide 37Slide 38Slide 39Slide 40FCFS Average Wait TimePredicting Wait Time in FCFSSlide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Preemptive SchedulersSlide 52Slide 53Slide 54Slide 55Slide 56Slide 57Slide 58Slide 59Slide 60Slide 61Slide 62Slide 63Slide 64Multi-Level QueuesSlide 66BSD 4.4 SchedulingWindows NT/2K SchedulingBank Teller SimulationSimulation Kernel LoopSimulation Kernel Loop(2)Slide 72Simple State DiagramUNIX State Transition DiagramWindows NT Thread StatesResourcesProcess HierarchiesUNIX OrganizationWindows NT OrganizationOperating Systems: A Modern Perspective, Chapter 6Slide 6-1Copyright © 2004 Pearson Education, Inc.Threads and Scheduling6Operating Systems: A Modern Perspective, Chapter 6Slide 6-2Copyright © 2004 Pearson Education, Inc.Announcements•Homework Set #2 due Friday at 11 am - extension•Program Assignment #1 due Thursday Feb. 10 at 11 am•Read chapters 6 and 7Operating Systems: A Modern Perspective, Chapter 6Slide 6-3Copyright © 2004 Pearson Education, Inc.Program #1: Threads - addenda•draw the picture of user space threads versus kernel space threads•user space threads yield voluntarily to switch between threads•because it’s user space, the CPU doesn’t know about these threads•your program just looks like a single-threaded process to CPU•Inside that process, use library to create and delete threads, wait a thread, and yield a thread•this is what you’re building•Advantage: can implement threads on any OS, faster - no trap to kernel, no context switch•Disadvantage: only voluntary scheduling, no preemption, blocked I/O on one user thread blocks all threadsOperating Systems: A Modern Perspective, Chapter 6Slide 6-4Copyright © 2004 Pearson Education, Inc.Program #1: Threads - addenda•each process keeps a thread table•analogous to process table of PCB’s kept by OS kernel for each process•Key question: how do we switch between threads?–need to save thread state and change the PC•PA #1 does it like this–scheduler is a global user thread, while your threads a and b are user, but local (hence on the stack)–stack pointer, frame pointerOperating Systems: A Modern Perspective, Chapter 6Slide 6-5Copyright © 2004 Pearson Education, Inc.Operating Systems: A Modern Perspective, Chapter 6Slide 6-6Copyright © 2004 Pearson Education, Inc.What is a Process?•A process is a program actively executing from main memory–has a Program Counter (PC) and execution state associated with it•CPU registers keep state•OS keeps process state in memory•it’s alive!–has an address space associated with it•a limited set of (virtual) addresses that can be accessed by the executing codeCodeDataMainMemoryProgramP1binaryCPUExecutionProgramCounter (PC)RegistersALUFetch Codeand DataWrite DataProcessHeapStackOperating Systems: A Modern Perspective, Chapter 6Slide 6-7Copyright © 2004 Pearson Education, Inc.How is a Process Structured in Memory?•Run-time memory image•Essentially code, data, stack, and heap•Code and data loaded from executable file•Stack grows downward, heap grows upwardUser stackHeapRead/write .data, .bssRead-only .init, .text, .rodataUnallocatedRun-time memoryaddress 0max addressOperating Systems: A Modern Perspective, Chapter 6Slide 6-8Copyright © 2004 Pearson Education, Inc.Multiple ProcessesMain MemoryCodeDataProcessP1HeapStackCodeDataProcessP2HeapStack•Process state, e.g. ready, running, or waiting•accounting info, e.g. process ID•Program Counter•CPU registers•CPU-scheduling info, e.g. priority•Memory management info, e.g. base and limit registers, page tables•I/O status info, e.g. list of open filesCodeMore Data,Heap, StackOSPCB for P2PCB for P1Operating Systems: A Modern Perspective, Chapter 6Slide 6-9Copyright © 2004 Pearson Education, Inc.Multiple ProcessesMain MemoryCodeDataProcessP1HeapStackCodeDataProcessP2HeapStackCodeMore Data,Heap, StackOSPCB for P2PCB for P1CPUExecutionProgramCounter (PC)ALUOperating Systems: A Modern Perspective, Chapter 6Slide 6-10Copyright © 2004 Pearson Education, Inc.Context SwitchingProcessManagerInterruptHandlerP1P2PnExecutable MemoryInitialization123457Interrupt896•Each time a process is switched out, its context must be saved, e.g. in the PCB•Each time a process is switched in, its context is restored•This usually requires copying of registersOperating Systems: A Modern Perspective, Chapter 6Slide 6-11Copyright © 2004 Pearson Education, Inc.Threads•A thread is a logical flow of execution that runs within the context of a process–has its own program counter (PC), register state, and stack–shares the memory address space with other threads in the same process,•share the same code and data and resources (e.g. open files)Operating Systems: A Modern Perspective, Chapter 6Slide 6-12Copyright © 2004 Pearson Education, Inc.Threads•Why would you want multithreaded processes?–reduced context switch overhead•In Solaris, context switching between processes is 5x slower than switching between threads–shared resources => less memory consumption => more threads can be supported, especially for a scalable system, e.g. Web server must handle thousands of connections–inter-thread communication is easier and faster than inter-process communication–thread also called a lightweight processOperating Systems: A Modern Perspective, Chapter 6Slide 6-13Copyright © 2004 Pearson Education, Inc.Threads•Process P1 is multithreaded•Process P2 is single threaded•The OS is multiprogrammed•If there is preemptive timeslicing, the system is multitaskedMain MemoryCodeDataProcess P1’s Address SpaceHeapCodeDataProcessP2HeapStackStackPC1Reg.StateThread 1StackPC2Reg.StateThread 2StackPC3Reg.StateThread 3Operating Systems: A Modern Perspective, Chapter 6Slide 6-14Copyright © 2004 Pearson Education, Inc.Processes


View Full Document

CU-Boulder CSCI 3753 - Threads and Scheduling

Download Threads and Scheduling
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 Threads and Scheduling 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 Threads and Scheduling 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?