Unit 3.7
Threads

Presenter Notes

本节幻灯片

Thread Usage

A word processor with three threads.

Presenter Notes

Thread Usage

A multithreaded Web server.

Presenter Notes

The Classical Thread Model

  • (a) Three processes each with one thread.
  • (b) One process with three threads.

Presenter Notes

The Classical Thread Model

  • The first column lists some items shared by all threads in a process.
  • The second one lists some items private to each thread.

Presenter Notes

The Classical Thread Model

Each thread has its own stack.

Presenter Notes

Implementing Threads

  • (a) A user-level threads package.
  • (b) A threads package managed by the kernel.

Presenter Notes

Hybrid Implementations

  • Multiplexing user-level threads onto kernel-level threads.

Presenter Notes

Thread Scheduling

  • (a) Possible scheduling of user-level threads
  • (b) Possible scheduling of kernel-level threads

Presenter Notes

Pop-Up Threads

Creation of a new thread when a message arrives.

  • (a) Before the message arrives.
  • (b) After the message arrives.

Presenter Notes

Thread safe

Conflicts between threads over the use of a global variable.

Presenter Notes

Thread safe

Threads can have private global variables.

Presenter Notes

POSIX Threads

Some of the Pthreads function calls.

Presenter Notes

POSIX Threads

Presenter Notes

Mutexes in Pthreads

Some of the Pthreads calls relating to mutexes.

Presenter Notes

Condition variables in Pthreads

Some of the Pthreads calls relating to condition variables.

Presenter Notes

Producer-consumer problem (pthreads)

Presenter Notes

Producer-consumer problem (pthreads)

Presenter Notes

Producer-consumer problem (pthreads)

Presenter Notes

Reference

  • Chapter 2: Processes and threads, Modern Operating Systems . Forth Edition, Andrew S. Tanenbaum
  • Chapter 11: Threads. Advanced Programming in the UNIX Environment, Third Edition. W. Richard Stevens,Stephen A. Rago

Presenter Notes