Threads Flashcards
What is the flow of Multithreaded Server Architecture
CLIENT > requests to > SERVER > creates thread to service request >
SERVER > continues to listen for additional client requests
Four benefits of Threads
Resource sharing
Responsiveness
Scalability
Economy
A benefit of threading which may allow continued execution if part of the process is blocked ( which is important for UI)
Responsiveness
A benefit of threads wherein threads share resources of process
(Easier than shared memory or message passing)
Resource sharing
Benefit of threads since
thread creation is CHEAPER than process creation;
Thread switching has LOWER OVERHEAD than context switching
Economy
Beneift of thread wherein the process can take advantage of the multiprocessor architecture
Scalability
_______ systems putting pressure on the programmer
Multicore / multiprocessor
Challenges faced because of using multicore / multiprocessor systems
Dividing activities Balancing Dtaa dependency Data splitting Testing and debugging
____ implies that a system can perform more than one task SIMULTANEOUSLY
Parallelism
___ supports more than one task making progress
(Single processor only)
(Scheduler is responsible for this)
Concurrency
A type of parallelism wherein you distribute SUBSET of the SAME DATA and perform the SAME operation across multiple cores
Data parallelism
A type of parallelism wherein you distribute threads across cores and perform DIFFERENT OPERATIONS per thread
Task parallelism
An increase in the number of threads implies that ___
Architectural support for threading also grows
CPUs have cores and h____
Eg: oracle sparc t4
hardware threads
For every thread in a Mutithreaded processes, there is a unique ____
Stack
Registers
This identifies the PERFORMANCE GAINS from ADDING ADDITIONAL CORES to an applictaion which has serial and parallel components
Amdahl’s Law
The higher the serial portion of an application, the ___ the performance gained by adding additional cores
Lesser
Formula for amdahl’s law
Speed-up = 1 / s-((1-s) / no of cores )
As N reaches infinity, speedup approaches __
1/serial portion
A type of parallelism wherein you distribute SUBSET of the SAME DATA and perform the SAME operation across multiple cores
Data parallelism
A type of parallelism wherein you distribute threads across cores and perform DIFFERENT OPERATIONS per thread
Task parallelism
An increase in the number of threads implies that ___
Architectural support for threading also grows
CPUs have cores and h____
Eg: oracle sparc t4
hardware threads
For every thread in a Mutithreaded processes, there is a unique ____
Stack
Registers
This identifies the PERFORMANCE GAINS from ADDING ADDITIONAL CORES to an applictaion which has serial and parallel components
Amdahl’s Law
The higher the serial portion of an application, the ___ the performance gained by adding additional cores
Lesser
Formula for amdahl’s law
Speed-up = 1 / s-((1-s) / no of cores )
As N reaches infinity, speedup approaches __
1/serial portion
A type of parallelism wherein you distribute SUBSET of the SAME DATA and perform the SAME operation across multiple cores
Data parallelism
A type of parallelism wherein you distribute threads across cores and perform DIFFERENT OPERATIONS per thread
Task parallelism
An increase in the number of threads implies that ___
Architectural support for threading also grows
CPUs have cores and h____
Eg: oracle sparc t4
hardware threads
For every thread in a Mutithreaded processes, there is a unique ____
Stack
Registers
This identifies the PERFORMANCE GAINS from ADDING ADDITIONAL CORES to an applictaion which has serial and parallel components
Amdahl’s Law
The higher the serial portion of an application, the ___ the performance gained by adding additional cores
Lesser
Formula for amdahl’s law
Speed-up = 1 / s-((1-s) / no of cores )
As N reaches infinity, speedup approaches __
1/serial portion
Threads managed by USER LEVEL THREAD LIBRARIES
User threads
Three primary thread libraries
POSIX pthreads
Windows threads
Java threads
Threads supported by the kernel
Ex: all general purpose OS
Kernel threads
Example of kernel threads
Windows
Mac OS
tru64 Unix
A multi threading model wherein many user level threads are mapped to a single kernel thread
Give examples
Many to one
Solaris green thread
GNU portable thread
A multithread model wherein creating a user level thread also creates a kernel thread
This model has more concurrency than many to one model but the number of threads are RESTRICTED due to OVERHEAD
Give examples
One to one model
Windows, linux, solaris 9 or later
A mulithread model wherein many user threads are mapped to many kernel threads which allows the OS to create SUFFICIENT number of kernel threads
Give examples
Solaris prior to ver 9
Windows with ThreadFiber package
A multithread model which is similar to m:m except it allows a user thread to be BOUND to a kernel thread
Give examples
IRIX
HP-UX
Tru64 UNIX
Solaris 8 and earlier
___ provides programmers with API for creating and manageing threads
Thread library
Two ways of implementing thread libraries
Library is ENTIRELY in USER SPACE
KERNEL-LEVEL LIBRARY supported by the OS
A POSIX standard API for creating and synchronization of threads
SPECIFIES behaviour of the thread library; IMPLEMENTATION is up to the development of the lirbary
Pthreads
Threads managed by the JVM
What are two ways to imlement this?
Java Threads
Extend thread class Implement runnable interface
Creation and management of threads are done by compilers and run-time libraries rather than programmers
What are three methods using this?
Implicit threading
ThreadPool
openMP
grand central dispatch
*other methods include Microsoft threading Building blocks (TBB) java.util.concurrent package
This method creates a number of threads IN A POOL where they await to work
What are advantages of this method?
Thread Pools
- slightly FASTER to service request with an existing thread than to create a new one
- allows a number of threads to be BOUND to the size of the pool
- CAN SEPARATE TASKS to be performed which allows strategies for running taskswh
What API supports thread pools
Windows API
A set of COMPILER DIRECTIVES and an API for c, c++, fortran which provides support for parallel programming in SHARED MEMORY environments
OpenMP
Blocks of that can run in parallel that is identified by OpenMP
Parallel regions
This compiler directive creates many threads as there are cores
pragma omp parallel
This method is an apple technology for mac os x and ios which allows IDENTIFICATION OF PARALLEL SECTIONS and manages most of the details in THREADING
Where is the block placed if you were to use this method?
Grand central dispatch
^{} which are placed in the dispatch queue
A type of dispatch queue wherein blocks are removed in FIFO order and queue is PER PROCESS called ___
Serial dispatch queues; main queue
Type of dispatch queue wherein blcoks are removed in FIFO order but several may be removed at a time
There are three system wide queues with priorities __,__,__
Concurrent dispatch queue
Low, default, high
5 Threading issues
Fork() and exec() system calls semantics Signal handling Thread cancellation Thread local storage Scheduler activations
What is the thread issue of fork() and exec()?
Fork() may:
- Duplicate only the calling thread
- Duplicate all threads
Exec() replaces the running process including all threads
This are used in the UNIX system to notify a process that a particular event has occured
What is used to process these?
Signals
Signal handlers
How does a signal reach a signal handler?
Signal is generated by an event > signal is delivered to a process > signal is handled by 1 / 2 signal handlers (kernel or user defined)
Every signal has a __ that a kernel runs when handling signals, ___ can override these
Default handlers ; user defined signal handlers
What is the threading issue of signal handling?
Issue on where the signal should be delivered for multi-threaded
- deliver to the thread which the signal applies
- deliver to every thread in the process
- deliver to certain threads in the process
- assign specific thread to receive all incoming signals
*if single threaded, signal is delivered to the process
A threading issue wherein you terminate a thread before it has finished wherein the thread to be cancelled is called the ___
Thread cancellation; target head
A general approach of thread cancellation wherein you terminate the target head immediately
Asynchronous cancellation
A general approach of thread cancellation wherein it allows the target head to periodically check if it should be cancelled
Deferred cancellation
What is the issue on thread cancellation?
Invoking thread cancellation only REQUESTS cancellation but actual cancellation depends on thread state
If thread ‘s state for cancellation is disabled, cancellation remains pending until thread enables it
What is the default type of thread cancellation wherein thread cancels only if it reaches CANCELLATION POINT
What handler is invoked by this type of cancellation?
Give an example
Deferred cancellation
Cleanup handler
Pthread_testcancel()
This allows each thread to have its own copy of data which is useful if you do not have control over the creation of threads
Thread local storage
Difference of tls and local variables
TLS are visible across function invocations while local variables are only visible during a single function
A form of communication to MAINTAIN APPROPRIATE NUMBER OF KERNEL THREADS ALLOCATED TO AN APPLICATION
Scheduler activations
A communication mechanism used by scheduler activations from the kernel to the ___ in the thread library
Upcalls
Upcall handler
What is the issue in scheduler activations?
Scheduler activations uses an intermediate data structure called LIGHTWEIGHT PROCESS (LWP) between user and kernel threads which serves as a VIRTUAL PROCESSOR
- Does each kernel thread need an lwp attached to it?
- how many lwp to create
The primary API for windows which implements 1:1 and kernel level thread
Windows API
Each thread contains
- thread id
- CONTEXT (register set, stacks, private storage area)
WHat does the register set reoresent in a thread
State of processor
What is the purpose of stacks in a thread?
Separate user and kernel stacks when thread runs user or kernel mode
Whatis the purpose of private data storage area in a thread?
This area is used by RUN-TIME LIBRARIES and DYNAMIC LINK LIBRARIES(DLLs)
A primary data structure of a thread which has a POINTER TO
- the process to which thread belongs
- to KTHREAD in kernel space
ETHREAD (executive thread block)
A primary data structure of a thread which handles SCHEDULING AND SYNC info, KERNEL MODE STACK, pointer to TEB in kernel space
KTHREAD (Kernel thread block)
A primary data structure of a thread which contains the thread id, USER MODE STACK, TLS, In user space
TEB (Thread environment block)
What is linux’s term for thread?
Task
Thread creation in linux is done by __ which allows child to share address space of parent task (process)
Clone() system call
Flag control for clone() where file system info is shared
Clone_fs
Flag control behaviour of clone same memory is shared
Clone_vm
Flag control behaviour of clone where signal handlers are shared
Clone_sighand
Flag control behaviour of clone() where set of open files are shared
Clone_files
In linux threads, ___ points to PROCESS DATA STRUCTURES (SHARED OR UNIQUE)
struct task_struct