• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/36

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

36 Cards in this Set

  • Front
  • Back
Why use threads?
1) Multiple tasks of an application can be implemented by threads

2) Process creation is heavy-weight, thread creation is light-weight

3) threads can simplify code, increase efficiency
What is a thread?
An independent stream of instructions that can be scheduled to run as such by the kernel
Threads exist _____ the process and ______ its resources
Threads exist within the process and share its resources
Each thread has its own:
essential resources (per-thread resources)

stack
registers
program counter
thread-specific data
*independent flow of control
threads are individually scheduled by ______
the kernel
each thread can be in any of the scheduling states (T/F)
true
Benefits of Threads
*Responsiveness
- multithreading an interactive application allows a program to continue running even if part of it is blocked or performing a lengthy operation
*Resource Sharing
- sharing resources may result in efficient communication and high degree of cooperation
*Economy
- thread is more light weight than process
*Scalability
- better utilization of multiprocessor architectures
Threads may be provided either at the ______ or by the ______
user level (user threads) or by the kernel (kernel threads)
user threads are supported ____ the kernel, ______ kernel support
above the kernel, without kernel support
kernel threads are supported and managed directly by ____
the kernel
Multi-threading models
ways to map user threads to kernel threads

Many to One
One to One
Many to Many
Many to One
Many user-level threads are mapped to one kernel thread

thread management is done by the thread library in user space

entire process will block if a thread makes a blocking system call

multiple threads are unable to run in parallel in multi-processors
One to One
One user-level thread maps to one kernel thread

allows other threads to run when a thread blocks

multiple threads can run in parallel on multiprocessors

creating a user thread requires creating a corresponding kernel thread (overhead)

limits the number of threads
Many to Many
Many user level threads are mapped to many kernel threads

solves shortcomings of 1:1 and m:1

create as many threads as necessary

corresponding threads can run in parallel on a multiprocessor
Two-level model
similar to many to many

allows a user thread to be BOUND to a kernel thread
Thread Libraries
provides programmer with API for creating and managing threads
2 ways to implement thread libraries
1) library entirely in user space with no kernel support

2) kernel level library supported by the OS
Pthreads
A POSIX standard API for thread creation and synchronization

specification for thread behavior

implementation is up to developer of the library
Threading Issues
1) Semantics of fork and exec system calls
2) thread cancellation of target thread
3) signal handling
4) thread pools
5) thread specific data
6) scheduler activities
Semantics of fork and exec
fork duplicates the whole single-threaded process

exec typically replaces the entire process, multithreaded or not
thread cancellation
termination a (target) thread before it has finished

2 approaches
2 approaches to thread cancellation
* asynchronous cancellation
- terminates the target thread immediately

* deferred cancellation
- allows the target thread to periodically check if it should be cancelled
Signal handling
signals are used in UNIX systems to notify a process that a particular event has occurred

* signal is generated by the occurrence of a particular event
* signal is delivered to a process
* once delivered, the signal must be handled
Synchronous signals (exceptions) are delivered to:
the same thread causing the signal
Asynchronous signals (I/O) can be delivered to:
* the thread to which the signal applies
* every thread in the process
* certain threads in the process
* specific thread to receive all signals for the process
One thread per request model has _______ problems
scalability (overhead to create a thread before each request, it may exhaust the resource)
Thread pools
Solve the scalability problems of the one thread per request model

* create a number of threads in a pool, where the sit and wait for work
* when received a request, they server wakens a thread and passes it to the request
* thread returns to the pool and completing the job
Advantage of thread pools
* Servicing a request with an existing thread is usually faster than waiting to create a new thread

* thread pool limits the number of threads that exist at any one point
Thread specific data
data is shared in multithreaded programs

thread specific data allows each thread to have its own copy of data
Light weight process (LWP)
an intermediate data structure between the user and kernel thread in many to many and two level models

to the user thread library, appears as virtual processors on which to schedule user threads
each LWP is attached to a _________
kernel thread
Upcall
scheduler activation notifies the thread library via upcalls
Linux Thread Flag:
CLONE_FS
file-system information is shared
Linux Thread Flag:
CLONE_VM
the same memory space is shared
Linux Thread Flag:
CLONE_SIGHAND
signal handlers are shared
Linux Thread Flag:
CLONE_FILES
the set of open files is shared