Unit 3.7
Threads

Presenter Notes

本节幻灯片


Thread Usage

A word processor with three threads.


Thread Usage

A multithreaded Web server.


The Classical Thread Model

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


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.


The Classical Thread Model

Each thread has its own stack.


Implementing Threads

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


Hybrid Implementations

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


Thread Scheduling

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


Pop-Up Threads

Creation of a new thread when a message arrives.

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


Thread safe

Conflicts between threads over the use of a global variable.


Thread safe

Threads can have private global variables.


POSIX Threads

Some of the Pthreads function calls.


POSIX Threads


Mutexes in Pthreads

Some of the Pthreads calls relating to mutexes.


Condition variables in Pthreads

Some of the Pthreads calls relating to condition variables.


Producer-consumer problem (pthreads)


Producer-consumer problem (pthreads)


Producer-consumer problem (pthreads)


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

results matching ""

    No results matching ""