Chapter 4 - Thread Concepts: 2004 Deitel & Associates, Inc. All Rights Reserved
Chapter 4 - Thread Concepts: 2004 Deitel & Associates, Inc. All Rights Reserved
Outline
4.1 Introduction
4.2 Definition of Thread
4.3 Motivation for Threads
4.4 Thread States: Life Cycle of a Thread
4.5 Thread Operations
4.6 Threading Models
4.6.1 User-Level Threads
4.6.2 Kernel-Level Threads
4.6.3 Combining User- and Kernel-Level Threads
4.7 Thread Implementation Considerations
4.7.1 Thread Signal Delivery
4.7.2 Thread Termination
4.8 POSIX and Pthreads
4.9 Linux Threads
4.10 Windows XP Threads
4.11 Java Multithreading Case Study, Part 1: Introduction to Java
Threads
Objectives
1
4.1 Introduction
• Thread
– Lightweight process (LWP)
– Threads of instructions or thread of control
– Shares address space and other global information with its
process
– Registers, stack, signal masks and other thread-specific data are
local to each thread
• Threads may be managed by the operating system or
by a user application
• Examples: Win32 threads, C-threads, Pthreads
2
4.2 Definition of Thread
Figure 4.1 Thread Relationship to Processes.
3
4.3 Motivation for Threads
• Thread states
– Born state
– Ready state (runnable state)
– Running state
– Dead state
– Blocked state
– Waiting state
– Sleeping state
• Sleep interval specifies for how long a thread will sleep
4
4.4 Thread States: Life Cycle of a Thread
Figure 4.2 Thread life cycle.
5
4.5 Thread Operations
6
4.6.1 User-level Threads
7
4.6.2 Kernel-level Threads
8
4.6.3 Combining User- and Kernel-level Threads
9
4.7.1 Thread Signal Delivery
10
4.7.2 Thread Termination
11
4.9 Linux Threads
12
4.10 Windows XP Threads
• Threads
– Actual unit of execution dispatched to a processor
– Execute a piece of the process’s code in the process’s
context, using the process’s resources
– Execution context contains
• Runtime stack
• State of the machine’s registers
• Several attributes
13
4.10 Windows XP Threads
Figure 4.8 Windows XP thread state-transition diagram.
14
4.11 Java Multithreading Case Study, Part I:
Introduction to Java Threads
Figure 4.9 Java threads being created, starting, sleeping and printing. (Part 1 of 4.)
15
4.11 Java Multithreading Case Study, Part I:
Introduction to Java Threads
Figure 4.9 Java threads being created, starting, sleeping and printing. (Part 3 of 4.)
16