This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Subsections Processes and Threads Benefts oF Threads vs Processes Multithreading vs. Single threading Some Example applications oF threads Thread Levels User-Level Threads (ULT) Kernel-Level Threads (KLT) Combined ULT/KLT Approaches Threads libraries The POSIX Threads Library: libpthread , <pthread.h> Creating a (DeFault) Thread Wait For Thread Termination A Simple Threads Example Detaching a Thread Create a Key For Thread-Specifc Data Delete the Thread-Specifc Data Key Set the Thread-Specifc Data Key Get the Thread-Specifc Data Key Global and Private Thread-Specifc Data Example Getting the Thread Identifers Comparing Thread IDs Initializing Threads Yield Thread Execution Set the Thread Priority Get the Thread Priority Send a Signal to a Thread Access the Signal Mask oF the Calling Thread Terminate a Thread Solaris Threads: < thread.h > Unique Solaris Threads unctions Suspend Thread Execution Continue a Suspended Thread Set Thread Concurrency Level Readers/Writer Locks Readers/Writer Lock Example Similar Solaris Threads unctions Create a Thread Get the Thread Identifer Yield Thread Execution Signals and Solaris Threads Terminating a Thread Creating a Thread-Specific Data Key Example Use oF Thread Specifc Data:Rethinking Global Variables Compiling a Multithreaded Application Preparing For Compilation Debugging a Multithreaded Program Threads: Basic Theory and Libraries This chapter examines aspects oF threads and multiprocessing (and multithreading). We will frts study a little theory oF threads and also look at how threading can be eFFectively used to make programs more eFfcient. The C thread libraries will then be introduced. The Following chapters will look at Further thead issues sucj a synchronisation and practical examples. Threads: Basic Theory and Libraries http://www.cs.cf.ac.uk/Dave/C/node29.html 1 of 24 1/27/09 7:30 AM Processes and Threads We can think of a thread as basically a lightweight process. In order to understand this let us consider the two main characteristics of a process: Unit of resource ownership-- A process is allocated: a virtual address space to hold the process image control of some resources (Fles, I/O devices...) Unit of dispatching- A process is an execution path through one or more programs: execution may be interleaved with other processes the process has an execution state and a dispatching priority If we treat these two characteristics as being independent (as does modern OS theory): The unit of resource ownership is usually referred to as a process or task. This Processes have: a virtual address space which holds the process image. protected access to processors, other processes, Fles, and I/O resources. The unit of dispatching is usually referred to a thread or a lightweight process. Thus a thread: Has an execution state (running, ready, etc.) Saves thread context when not running Has an execution stack and some per-thread static storage for local variables Has access to the memory address space and resources of its process...
View Full Document
This note was uploaded on 07/16/2009 for the course SYSC 3303 taught by Professor Shramp during the Spring '09 term at Carleton CA.
- Spring '09