Unformatted text preview:

COT 4600 Operating Systems Fall 2009Lecture 19Virtualization of threadsBasic primitives for processor virtualizationSlide 5The state of a thread and its associated virtual address spaceProcessor sharingThread states and state transitionsSwitching the processor from one thread to anotherSlide 10Slide 11Implementation of YIELDSlide 13More about thread creation and terminationSwitching threads with dynamic thread creationSlide 16Slide 17Slide 18COT 4600 Operating Systems Fall 2009Dan C. MarinescuOffice: HEC 439 BOffice hours: Tu-Th 3:00-4:00 PM22222Lecture 19Last time: Enforcing Modularity in MemoryToday:Sharing a processor among multiple threadsImplementation of the YIELDCreating and terminating threadsPreemptive schedulingNext Time:Thread primitives for sequence coordinationVirtualization of threadsImplemented by the operating system for the three abstractions:1. Threads  a thread is a virtual processor; a module in execution1. Multiplexes a physical processor2. The state of a thread: (1) the reference to the next computational step (the Pc register) + (2) the environment (registers, stack, heap, current objects).3. Sequence of operations:1. Load the module’s text2. Create a thread and lunch the execution of the module in that thread.4. A module may have several threads.5. The thread manager implements the thread abstraction.1. Interrupts  processed by the interrupt handler which interacts with the thread manager2. Exception  interrupts caused by the running thread and processed by exception handlers3. Interrupt handlers run in the context of the OS while exception handlers run in the context of interrupted thread.Basic primitives for processor virtualizationMemoryCREATE/DELETE_ADDRESS SPACEALLOCATE/FREE_BLOCKMAP/UNMAPUNMAPInterpreterALLOCATE_THREAD DESTROY_THREADEXIT_THREAD YIELDAWAIT ADVANCETICKETACQUIRE RELEASECommunication channelALLOCATE/DEALLOCATE_BOUNDED_BUFFERSEND/RECEIVEThe state of a thread and its associated virtual address spaceLecture 18 6Processor sharingPossible because threads spend a significant percentage of their lifetime waiting for external events.Called:Time-sharingProcessor multiplexingMultiprogrammingMultitaskingThe kernel must support a number of functions:Creation and destruction of threadsAllocation of the processor to a ready to run threadHandling of interruptsScheduling – deciding which one of the ready to run threads should be allocated the processor Lecture 19 7Thread states and state transitionsLecture 19 8Switching the processor from one thread to anotherThread creation: thread_id ALLOCATE_THREAD(starting_address_of_procedure, address_space_id);YIELD  function implemented by the kernel to allow a thread to wait for an event.Save the state of the current threadSchedule another threadStart running the new thread – dispatch the processor to the new threadYIELD cannot be implemented in a high level language, must be implemented in the machine language.can be called from the environment of the thread, e.g., C, C++, Javaallows several threads running on the same processor to wait for a lock. It replaces the busy wait we have used before. Lecture 19 9Lecture 6 10Implementation of YIELDLecture 19 12More about thread creation and terminationWhat if want to create/terminate threads dynamically  we have to:Allow a tread to self-destroy and clean-up -> EXIT_THREADAllow a thread to terminate another thread of the same application DESTRY_THREADWhat if no thread is able to run  create a dummy thread for each processor called a processor_thread which is scheduled to run when no other thread is availablethe processor_thread runs in the thread layer the SCHEDULER runs in the processor layerThe procedure followed when a kernel starts----------------------------------------------------------------------- Procedure RUN_PROCESSORS() for each processor do allocate stack and setup processor thread /*allocation of the stack done at processor layer shutdown  FALSE SCHEDULER() deallocate processor_thread stack /*deallocation of the stack done at processor layer halt processor Lecture 19 14Switching threads with dynamic thread creationSwitching from one user thread to another requires two stepsSwitch from the thread releasing the processor to the processor threadSwitch from the processor thread to the new thread which is going to have the control of the processorThe last step requires the SCHEDULER to circle through the thread_table until a thread ready to run is foundThe boundary between user layer threads and processor layer thread is crossed twiceExample: switch from thread 1 to thread 6 using YIELDENTER_PROCESSOR_LAYEREXIT_PROCESSOR_LAYERLecture 6 15Lecture 19 16Lecture 19 17Lecture 19


View Full Document

UCF COT 4600 - Lecture Notes

Download Lecture Notes
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 Notes 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 Notes 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?