Download presentation
Presentation is loading. Please wait.
1
CS 843 - Distributed Computing Systems Chin-Chih Chang, chang@cs.twsu.edu An Introduction to Threads
2
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Thread vs. Process A thread – lightweight process (LWP) is a basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. A traditional (heavyweight) process has a single thread of control. If the process has multiple threads of control, it can do more than one task at a time.
3
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Single and Multithreaded Processes
4
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Motivation An application typically is implemented as a separate process with several threads of control. For example, a web browser might have one thread display images or text while another thread retrieves data from the network. It is more efficient for a process that contains multiple threads to serve the same purpose. This approach would multithreaded the web-server process.
5
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Advantages Responsiveness: Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user. Resource Sharing: Threads share the memory and the resources of the process to which they belong. Economy: Allocating memory and resources for process creation is costly. Utilization of MP (multiprocessor) Architectures: Each thread may be running in parallel on a different processor.
6
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Disadvantages Complexity: Threads introduce another level of complexity to the program development. Debugging Difficulty: Multithreads are difficult to debug and test. Race condition: Race conditions can appear without proper locking and data synchronization. Deadlock: Deadlocks can can happen whenever multiple locks are used for date synchronization. Non-thread-safe environment: Programs can arise in a non-thread-safe environment because of different thread library.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.