T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of...

16
THREADS Lecture 5 1 L . M o h a m m a d R . A l k a f a g e e

description

HEAVYWEIGHT PROCESSES ( CONT.) Every time a swap occurs overhead increase because of all the information must be saved. To minimize this overhead time the operating system support the implementation of threads or lightweight processes. Threads are supports at both kernel and user level and can be managed by either operating system or the application that created them. 3 L. Mohammad R.Alkafagee

Transcript of T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of...

Page 1: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

L. Moham

mad R.Alkafagee

1

THREADS

Lecture 5

Page 2: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

2

L. Moham

mad R.Alkafagee

HEAVYWEIGHT-PROCESSESThe cooperation of traditional processes also known as heavyweight processes which have the following characteristics:

They require space in main memory where they reside during their execution.They pass through several states from their initial entry into the computer system to their completion :ready, running, waiting, new, etc.These processes are often swapped between main memory and secondary memory during their execution to accommodate multiprogramming and to take advantage of virtual memory.

Page 3: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

3

L. Moham

mad R.Alkafagee

HEAVYWEIGHT PROCESSES (CONT.)

Every time a swap occurs overhead increase because of all the information must be saved.To minimize this overhead time the operating system support the implementation of threads or lightweight processes.

Threads are supports at both kernel and user level and can be managed by either operating system or the application that created them.

Page 4: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

4

L. Moham

mad R.Alkafagee

HEAVYWEIGHT PROCESSES (CONT.)

The aim of having multiple threads of execution is :

To maximize degree of concurrent execution between operations

To enable the overlap of computation with input and output

To enable concurrent processing on multiprocessors.

Page 5: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

5

L. Moham

mad R.Alkafagee

Page 6: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

6

L. Moham

mad R.Alkafagee

Page 7: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

7

L. Moham

mad R.Alkafagee

:THREAD STATSNew :create new thread.Runnable:

Ready :Ready to executeRunning :Thread in execution.Waiting : Thread Wait until a specific event has occurred.Timed Waiting : Thread putting for specified amount of time.Terminated : Terminate execution and release resources.Blocked : Waiting for I/O to complete.

Page 8: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

8

L. Moham

mad R.Alkafagee

THREADS STATES

New

Runnable

WaitingTimed

WaitingTerminate

d Blocked

Program starts the thread

Notify all

wait Wai

t sle

ep

Inte

rval

ex

pire

Task

co

mpl

ete

d

I/O request

Enter synchronized

statement

Acquire lockI/O completes

Page 9: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

9

L. Moham

mad R.Alkafagee

INTERNAL VIEW FOR RUNNABLE STATE

Ready Running

RUNNABLE

Operating System Dispatches a thread

Quantum expires

Operating system’s internal view of java’s Runnable state

Page 10: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

10

L. Moham

mad R.Alkafagee

THREAD CONTROL BLOCK (TCB)It contains basic information about a thread such as:

*Thread ID. *Thread state.

*CPU information. *Thread priority.

*A pointer to the process that created the thread.

Page 11: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

11

TYPES OF THREADS:1.User Threads :

L. Moham

mad R. Alkafagee

Page 12: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

12

L. Moham

mad R.Alkafagee

2.KERNAL THREAD

Page 13: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

13

L. Moham

mad R.Alkafagee

MULTITHREADING MODELS :

1.Many-to-One Model: maps many user-level threads to one kernel thread.

2.One-to-One Model : maps each user thread to a kernel thread.

3.Many-to-Many Model: multiplexes many user-level threads to a smaller or equal number of kernel threads.

Page 14: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

14

L. Moham

mad R.Alkafagee

:)Many-to-One(Multithreading Models

K

User Thread

Kernel Thread

Examples:Solaris Green ThreadsGNU Portable Threads

Page 15: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

15

L. Moham

mad R.Alkafagee

)Multithreading Models (One-to-One

K

User Thread

Kernel ThreadK K

ExamplesWindows NT/XP/2000LinuxSolaris 9 and later

Page 16: T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.

16

)Multithreading Models (Many-to-Many

K K K

User Thread

Kernel Thread

Examples:Solaris prior to version 9Windows NT/2000 with the ThreadFiberpackage