Docsity

OS lectures slides which include processes,threads,process,scheduling,semaphores, Slides of Operating Systems

Partial preview of the text

Download OS lectures slides which include processes,threads,process,scheduling,semaphores and more Slides Operating Systems in PDF only on Docsity!

Operating System

FALL 2019

Foundation University

Islamabad Campus

LEC#02-Threads

Prepared by

Dr. Shariq BASHIR

[email protected]

Quiz#

  • Next week (10 October) in Thursday class.
  • (^) Will be from LECTURE#01 (Processes)

 a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0  a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0  a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0

Running Ready Ready

a := 1  b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 b := a + 1  c := b + 1 read a file a := b - c c := c * b b := 0

Timeout

Timeout

How process state changes

a := 1 b := a + 1 c := b + 1  read a file a := b - c c := c * b b := 0  a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0  a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0

Ready Running Ready

a := 1  read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0

I/O

I/O

How process state changes

a := 1 b := a + 1 c := b + 1  a := b - c c := c * b b := 0 c := 0 a := 1  read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1  read a file a := b - c c := c * b b := 0

Running Blocked Ready

I/O

I/O

How process state changes

a := 1  read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1  read a file a := b - c c := c * b b := 0

Blocked Blocked Running

a := 1 b := a + 1 c := b + 1  a := b - c c := c * b b := 0 c := 0 How process state changes

The Next Process to

Run cannot be simply

selected from the front

a := 1 read a file  b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1  read a file a := b - c c := c * b b := 0

Blocked Ready Running

a := 1 b := a + 1 c := b + 1  a := b - c c := c * b b := 0 c := 0 a := 1 b := a + 1 c := b + 1 a := b - c  c := c * b b := 0 c := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b  b := 0 c := 0

Timeout

Timeout

How process state changes

a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0  c := 0 a := 1 b := a + 1 c := b + 1  read a file a := b - c c := c * b b := 0

Blocked Running Ready

a := 1 read a file  b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 read a file b := a + 1  c := b + 1 a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1  a := b - c c := c * b b := 0

Timeout

Timeout

How process state changes

Single Threaded Approaches  A single execution path per process, in which the concept of a thread is not recognized, is referred to as a single-threaded approach  MS-DOS, some versions of UNIX supported only

Multithreaded Approaches  A Java run-time environment is a system of one process with multiple threads; Windows, some UNIXes, support multiple multithreaded processes.

Benefits of Threads

Takes

less time

to create

a new

thread

than a

process

Less time to

terminate a

thread than

a process

Switching

between two

threads takes

less time

than

switching

between

processes

Threads

enhance

efficiency in

communicatio

n between

programs

Threads   In an OS that supports threads, scheduling is done on a thread basis

Types of Threads User Level Thread (ULT) Kernel level Thread (KLT)

User-Level Threads (ULTs)  Thread management is done by the application  The kernel is not aware of the existence of threads