This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 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 24 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 24 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 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ThreadsSingle and Multithreaded ProcessesUser ThreadsKernel ThreadsThread ModelsMany-to-One ModelOne-to-one ModelMany-to-Many ModelMany-to-Many ModelThreadThreading IssuesPthreadsSolaris 2 ThreadsSolaris ProcessNachos ThreadThread StatesNachos Thread OperationsNachos Thread OperationMechanics of Thread SwitchingSWITCH routineThreads and SchedulingScheduler RoutinesRun() scheduler methodLightweight and Heavyweight Threads3/9/2003 B.Ramamurthy 1ThreadsStill Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)3/9/2003 B.Ramamurthy 2Single and Multithreaded ProcessesThread specificData (TSD)Code3/9/2003 B.Ramamurthy 3User ThreadsThread management done by user-level threads libraryExamples-POSIX Pthreads- Solaris threads-Nachos Thread3/9/2003 B.Ramamurthy 4Kernel ThreadsSupported by the KernelExamples- Windows 95/98/NT/2000-Solaris-Tru64 UNIX-BeOS- Linux3/9/2003 B.Ramamurthy 5Thread ModelsMany to One: Many user-level threads mapped to single kernel thread. Used on systems that do not support kernel threads. One to One Each user-level thread maps to kernel thread. Examples- Windows 95/98/NT/2000-OS/2Many to Many3/9/2003 B.Ramamurthy 6Many-to-One Model3/9/2003 B.Ramamurthy 7One-to-one Model3/9/2003 B.Ramamurthy 8Many-to-Many ModelAllows many user level threads to be mapped to many kernel threads.Allows the operating system to create a sufficient number of kernel threads.Solaris 2 Windows NT/2000 with the ThreadFiberpackage3/9/2003 B.Ramamurthy 9Many-to-Many Model3/9/2003 B.Ramamurthy 10ThreadThreadData StructuresThread controlmethods3/9/2003 B.Ramamurthy 11Threading IssuesThread life cycle management Thread create, thread suspend, thread yield, thread resume, thread sleep, thread kill, thread start, thread stopThread specific dataThread poolsSignal handling3/9/2003 B.Ramamurthy 12Pthreadsa POSIX standard (IEEE 1003.1c) API for thread creation and synchronization.API specifies behavior of the thread library, implementation is up to development of the library.Common in UNIX operating systems.Simply a collection of C function.3/9/2003 B.Ramamurthy 13Solaris 2 Threads3/9/2003 B.Ramamurthy 14Solaris Process3/9/2003 B.Ramamurthy 15Nachos ThreadNachos process consists of  An address space Executable code Stack space for automatic (local) variables Heap space for global variables A single thread of control Other object such as file descriptors We allow multiple threads of control to execute concurrently.3/9/2003 B.Ramamurthy 16Thread StatesThread()JUST_CREATEDFork()Scheduler dispatchREADYRUNNINGEvent occursWaiting for an eventBLOCKED3/9/2003 B.Ramamurthy 17Nachos Thread OperationsCreation: Thread *Thread(char *debugName);Create a thread but no code attached yet. Fork (voidfunctionPtr func, int arg);Associate a function to be executed by the thread.Control: void Yield()Suspend the current thread (calling thread..self) and select a new one for execution from the Ready queue3/9/2003 B.Ramamurthy 18Nachos Thread Operation void Sleep()Suspend the current thread, change its state to BLOCKED; It will return to READY on when a particular event takes place. void Finish()Terminate current thread. Return all data structures held to the system; Finish sets the gloabal variable threadToBe Destroyed to point to current thread, then calls sleep to effectively terminate the thread. Scheduler will start running another thread, this thread will examine threadToBeDestroyed and finish it off.3/9/2003 B.Ramamurthy 19Mechanics of Thread SwitchingSwitching the CPU from one thread to another involves suspending the current thread, switching its state (eg: registers), then restoring the state of the thread being switched to. Thread switch is complete the moment the program counter is loaded into the PC.3/9/2003 B.Ramamurthy 20SWITCH routineRoutine switch( oldThread, newThread) actually performs a thread switch. Routine switch is written in assembly language and therefore is machine dependent.Semantics of switch:1. Save all registers in oldThread’s context block.2. Save the return address in the context block.3. Load new values into the register from the context block of next thread.4. Replace PC with the saved PC in the process table; now switch is done.5. Context switch has taken place.3/9/2003 B.Ramamurthy 21Threads and SchedulingThreads that are ready to run are kept in a ready to run queue.Scheduler is invoked when ever time slice is over or if the current thread wants to give up the CPU.Threads suspended move to the end of the ready list.3/9/2003 B.Ramamurthy 22Scheduler RoutinesVoid ReadyToRun(Thread *thread)Make the thread ready to run and place it in the ready to run listReadyToRun is invoked for example by the Fork routine.Thread FineNextToRun()Select a ready thread and return it.3/9/2003 B.Ramamurthy 23Run() scheduler methodvoid Run(Thread *nextThread)Suspend the current thread and switch to the new one.Semantics:1. Check if the current thread overflowed its stack. If yes, reset it.2. Change the state of new thread to RUNNING.3. Invoke switch to switch to the next thread.4. If the previous thread is to be destroyed then do it. (Threads cannot terminate themselves.)We will discuss thread synchronization later.3/9/2003 B.Ramamurthy 24Lightweight and Heavyweight ThreadsLight weight: Creating a thread using Thread class and then coercing the code to execute using fork.Heavy weight: Hardcode the code to execute for the current thread.See threads/threadtest.cc of nachos for


View Full Document

UB CSE 421 - Threads

Documents in this Course
Security

Security

28 pages

Security

Security

20 pages

Security

Security

52 pages

Security

Security

20 pages

Load more
Download Threads
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 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 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?