Index
Computer Science
Operating System
Operating System Concepts
Threads

Threads

Overview

资源按进程分配,调度以线程为基本单位。

Benefits

  • Responsiveness
  • Resource Sharing
  • Economy
  • Utilization of MultiProcessor Architectures

Multithreading Models

img

There are two supporting levels for multithreading:

User Threads

Thread management done by user-level threads library.

Three primary thread libraries:

  • POSIX Pthreads
  • Win32 threads
  • Java threads

Kernel Threads

Supported by the Kernel

Examples

  • Windows 95/98/NT/2000/XP
  • Solaris
  • Tru64 UNIX
  • BeOS
  • Linux

Note: No One-to-Many Model exists

Many-to-One

Many user-level threads mapped to single kernel thread.

Used on systems that do not support kernel threads.

  • Green Threads
  • GNU Portable Threads

One-to-One

Each user-level thread maps to kernel thread.

  • Windows 95/98/NT/2000/XP
  • OS/2

Many-to-Many

Allows many user level threads to be mapped to many kernel threads.

Allows the operating system to create a sufficient number of kernel threads.

  • Solaris 2
  • Windows NT/2000 with the ThreadFiber package

One popular variation on the many-to-many model still multiplexes many user-level threads to a smaller or equal number of kernel threads but also allows a user-level thread to be bound to a kernel thread. This variation, sometimes referred to as the two-level model, is supported by operating systems such as IRIX, HP-UX, and Tru64 UNIX.

Thread Libraries

POSIX Pthreads

A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization

API specifies behavior of the thread library, implementation is up to development of the library

Common in UNIX operating systems (Solaris, Linux, Mac OS X)

Windows Threads

Implements the one-to-one mapping

Each thread contains:

  • A thread id
  • Register set
  • Separate user and kernel stacks
  • Private data storage area

The register set, stacks, and private storage area are known as the context of the threads

Linux Threads

Linux refers to them as tasks rather than threads.

Thread creation is done through clone() system call.

clone() allows a child task to share the address space of the parent task (process).

Java Threads

Java threads may be created by:

  • Extending Thread class
  • Implementing the Runnable interface

Java threads are managed by the JVM.

Created by sine. Last modification: 2022-06-18 17:27:04