thread by group iii kathryn bean and wafa’ jaffal

23
Thread By Group III Kathryn Bean and Wafa’ Jaffal

Upload: lester-henry

Post on 18-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Thread

By Group IIIKathryn Bean and Wafa’ Jaffal

Page 2: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Topics Covered Process vs. Thread Multithreading Benefits of Threads Thread States Different Thread Types Mapping between Processes and Threads Threading Issues Conclusion

Page 3: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Process vs. Thread, Process: Related to resource ownership

Have a virtual address space which holds the process image

Protected access to processors, other processes, files, and I/O resources

Page 4: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Process vs. Thread, Thread: Related to program execution

Saved thread context when not running Has an execution stack Some per-thread static storage for local

variables Access to the memory and resources of

its process• all threads of a process share this

Page 5: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Process vs. Thread

Single-Threaded

PCB

Addr.

Space

Kernel

Stack

User

Stack

PCBAddr.

Space

Thread CB

User Stack

Kernel Stack

Thread CB

User Stack

Kernel Stack

Thread CB

User Stack

Kernel Stack

Thread CB

User Stack

Kernel Stack

Multithreaded

Page 6: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Multithreading MS-DOS - a single thread UNIX - multiple user processes but

only supports one thread per process

Java Run-Time engine - one process, multiple threads

Windows 2000, Solaris, Linux, Mach, and OS/2 - multiple threads

Page 7: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Multithreading

1 Process 1 Thread

M Processes 1 Thread per Process

1 Process M Threads

M Processes N Threads

Page 8: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Benefits of Threads Takes less time to create a new thread

than a process Less time to terminate a thread than a

process Less time to switch between two threads

within the same process Since threads within the same process

share memory and files, they can communicate with each other without invoking the kernel

Page 9: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Uses of Threads

Foreground to background work Asynchronous processing Speed execution Modular program structure

Page 10: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Remote Procedure Call Using Threads

Server

Time

RPC Request RPC Request

RPC Using Single Thread

Server

Page 11: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Remote Procedure Call Using Thread

Server

Time

RPC Request

Server

RPC Request

Thread 1

Thread 2

Page 12: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Threads within Process States Suspending a process involves

suspending all threads of the process since all threads share the same address space

Termination of a process, terminates all threads within the process

Page 13: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Thread States States associated with a change in

thread state Spawn

• Spawn another thread Block Unblock Finish

• Deallocate register context and stacks

Page 14: Thread By Group III Kathryn Bean and Wafa’ Jaffal

User-Level Threads (ULT) All thread management is done by

the application The kernel is not aware of the

existence of threads Example:

POSIX Pthread Mach C-thread Solaris 2 UI-thread

Page 15: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Kernel-Level Threads (KLT) Kernel maintains context

information for the process and the threads

Scheduling is done on a thread basis W2K, Linux, and OS/2 are examples

of this approach

Page 16: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Combined Approaches Example is Solaris Thread creation done in the user space Bulk of scheduling and synchronization of

threads done in the user space Multiple ULT from a single application are

mapped onto some number of KLT

Page 17: Thread By Group III Kathryn Bean and Wafa’ Jaffal
Page 18: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Relationship Between Threads and Processes

Threads:Process Description Example Systems

1:1 Each thread of execution is aunique process with its ownaddress space and resources.

Traditional UNIX implementations

M:1 A process defines an addressspace and dynamic resourceownership. Multiple threadsmay be created and executedwithin that process.

Windows NT, Solaris, OS/2,OS/390, MACH

Page 19: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Relationship Between Threads and Processes

Threads:Process Description Example Systems

1:M A thread may migrate from oneprocess environment toanother. This allows a threadto be easily moved amongdistinct systems.

Ra (Clouds), Emerald

M:M Combines attributes of M:1and 1:M cases

TRIX

Page 20: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Thread Issue Cancellation

Target thread - thread to be cancelled Asynchronous cancellation Deferred cancellation

Thread pool Create a number of threads at process

startup and place them into a pool

Page 21: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Conclusion Responsiveness Resource sharing Economy Utilization of multiprocessor

architectures Threads synchronization

Page 22: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Thank You

Questions?

Page 23: Thread By Group III Kathryn Bean and Wafa’ Jaffal

Bibliography

W. Stallings, Operating SystemsPrentice-Hall, 1998

A. Silberschatz, P. Galvin, G. Gagne, Operating System ConceptsJohn Wiley & Sons, Inc. 2002