+ All Categories
Home > Documents > Introduction to Operating Systems – Windows process and thread management In this lecture we will...

Introduction to Operating Systems – Windows process and thread management In this lecture we will...

Date post: 20-Dec-2015
Category:
View: 226 times
Download: 1 times
Share this document with a friend
21
Introduction to Operating Systems – Windows process and thread management • In this lecture we will cover • Threads and processes in Windows • Thread priority and scheduling • Thread synchronisation • Interprocess communication
Transcript
Page 1: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Introduction to Operating Systems – Windows process and thread

management

• In this lecture we will cover

• Threads and processes in Windows

• Thread priority and scheduling

• Thread synchronisation

• Interprocess communication

Page 2: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Windows structure overview

USER APPLICATION SYSTEM SYSTEM SUBSYSTEM DLL ENVIRONMENT SUBSYSTEM SUPPORT SERVICES

NTDLL.DLL USER MODE KERNEL MODE EXECUTIVE

API

I/O MANAGER

CACHE MANAGER

PROCESS & THREAD MANAGER

SECURITY REFERENCE MONITOR

VIRTUAL MEMORY MANAGER

Win32 USER and GDI (Graphics engine)

FILE SYSTEMS

PLUG & PLAY MANAGER

POWER MANAGER

CONFIGUARION MANAGER

OBJECT MANAGER /

LOCAL PROCEDURE CALL

Graphics drivers

DEVICE

DRIVERS KERNEL

HARDWARE ABSTRACTION LAYER (HAL)

Page 3: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Processes and threads

• In Windows a process consists of program code, execution context ( the address space of the process plus such things as the access token) resources allocated to the process i.e. handles, one or more threads

• Threads are the units of execution – they execute program code using the processes context and resources

Page 4: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• A thread has its own context (register values including instruction pointer, execution stack, and such things as scheduling priority)

• Threads are scheduled onto the processor, not a process

Page 5: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Processes and threads are managed by 2 components in Windows:

• the process and thread manager

and

• the kernel

Page 6: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

kernel• The kernel is responsible for:

– Thread scheduling– Interrupt and exception handling– Low level processor synchronisation– Recovery after power failure

• In normal Operating Systems the kernel refers to all the operating systems components that run in kernel mode. In Windows as we have seen this applies to all the Windows Executive components (everything below the line in the diagram).

Page 7: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• However, perversely, Windows applies the name kernel to just one component - a low level layer of the OS that manages much of the execution of threads within processes

• The kernel uses objects to represent and manage low level threads and processes

• However these kernel objects are different from those managed by the Object Manager

• They are lower level and provide support for the higher level objects used by the Object Manager

Page 8: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Process and thread manager• Process manager is part of the Windows

Executive and implements the representation of processes and threads that are available to other parts of the Executive and provides high level services to manage and control processes and threads

• Process and thread manager provides functions to– Create and destroy processes– Control resource allocation to processes– Keep track of information about processes and threads

Page 9: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Processes are created by other processes by making a CreateProcess system call

• Unlike Unix/Linux the parent and child process are independent of each other – remember fork in Unix/Linux creates the child as a copy of the parent and hence has a copy of the parents address space

• In Windows child process has completely separate address space, etc.

• Hence Windows does not keep track of process hierarchies

Page 10: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Thread scheduling

• Windows maintains a list of threads that are in the system

• Threads may be in one of several different states

• Ready – thread can execute but waiting for a processor

• Running – running on a processor• Standby - selected to run next on a

processor

Page 11: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Waiting – unable to execute until some event occurs (typically I/O)

• Terminated

• All processes have at least one thread known as the base thread – created when the process is created

Page 12: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• The kernel implements the dispatcher code, which determines which thread to run next

• The dispatcher implements pre-emptive scheduling among threads

• The dispatcher schedules threads without reference to the process they belong to – hence a process that has more threads will if everything else is equal have a greater share of the processor

Page 13: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• The scheduling algorithm is based on a multilevel priority queue approach with each thread having a priority and hence belonging to a given queue

• A ready thread is placed in the queue which represents its assigned priority

• There are 32 priority queue levels designated by numbers with 31 highest priority and 0 lowest

• Dispatcher starts with highest priority queue and schedules threads in order in queue in round robin fashion

Page 14: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Each thread is given a time quantum in which to execute and it either blocks itself waiting on some I/O event or synchronisation event or the quantum expires

• Once a given queue is empty, the dispatcher then proceeds to the next lowest priority queue and so on until the queues are all empty or a higher level priority thread enters a ready state i.e. one of the higher level queues is now no longer empty – and dispatcher pre-empts lower priority running thread

Page 15: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Highest priority levels (16-31) is for real-time threads (needing immediate responsiveness) – the real-time priorities are static

• Lower priority levels (0-15) are for dynamic priority threads

• A processes base thread is given a base priority – which is the minimum priority a thread can have

Page 16: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Each process has:

• a base priority class (a range of priority levels which the define the possible range of base priorities) and

• a base priority level which specifies the relative base priority a threads should have in the base priority class

Page 17: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Each thread then takes on priority values dynamically i.e. it changes over time

• e.g. if the thread is delayed waiting on an I/O event, when the I/O event occurs and the thread becomes ready again, its priority is increased temporarily.

• The size of the increase depends on the length of the wait – the longer the wait the greater the increase in priority

Page 18: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Traps and exception handling• Kernel implements a trap handler which deals

with hardware interrupts and processor exceptions• The trap handler disables interrupts, determines

the cause of the interrupt, saves processor state, re-enables interrupts and dispatches code to deal with type of interrupt/exception found (Interrupt service routine for I/O events or traps from running code to request some service or exception handler to handle problems such as attempt to execute invalid instruction)

Page 19: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Thread synchronisation

• Windows provides a set of dispatcher objects which can be used for synchronisation of thread behaviour

• These dispatcher objects can be in a signalled state (when the event that the thread is waiting for occurs) or a unsignaled state (when the event has not yet occurred)

Page 20: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

• Event objects represent events such as I/O events – when the relevant event occurs the object manager sets the event object to the signalled state

• Mutex objects provide mutual exclusion – only one thread can have a mutex object – it does this by setting the object into an unsignaled state. Once the thread completes its activity it sets the mutex object to the signalled state

• Waitable timer objects – these objects remain unsignaled until a given time has elapsed

Page 21: Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.

Interprocess communication• Threads (and hence also processes) can

communicate using a variety of methods• Pipes – work very similar to Unix – unidirectional

communication via a shared buffer• Sockets – similar to pipes but usually connect

processes and threads on different machines• Remote procedure calls – allows a thread in one

process to invoke the execution of code in different processes address space

• File sharing is also implemented


Recommended