slides06 Flashcards
lightweight multi-processing
- multi tasks within an application implemented by separate threads
- cheaper/faster to create and faster to switch
motivation for lightweight multi-processing
- process creation is heavyweight: application can be slowed down by process creation, termination and management overhead
- use process pools to reduce overhead of creation on demand
- thread creation is more lightweight
- threads simplify code (modularization) and increase efficiency
processes vs threads
PROCESSES
- create a new address space at process creation
- allocate resources at creation
- need IPC to share data - each process has its own address space
- deeper isolation for security and fault tolerance
THREADS
- same address space
- quicker creation times
- sharing through shared memory
- fault sharing between all threads within a process
disadvantages of threads
- threads don’t have the same fault tolerance as processes
- overheard for handing client request to a thread
benefits of multithreading
- responsiveness: allows for continued execution if part of process is blocked
- resource sharing: threads come with shared memory (no need for creation)
- economy: cheaper than process creation, thread switching has lower overhead than context switching
- scalability: process can take advantage of multiprocess architecture
paralellism
system can perform more than one task simultaneously
types of paralellism in multi-core programming
- data paralellism:
-distributes subsets of data across mulitple cores, same operation on each set of data
- three steps: splitting -> solving sub-problems -> combininh - task parallelism: distributing threads across cores, each thread performs a unique operation
threading models
- user-level threads
- kernel-level threads
- hybrid threads
user-level threads
- many-to-one
- many user-level threads mapped to a single kernel thread
- one thread blocking causes all to block
- multiple threads cannot run in parallel in multi-core system because kernel level has one thread
kernel-level threads
- one-to-one
- each user-level thread maps to a kernel thread
- more concurrency
- number of threads per process restricted due to overhead
hybrid threads
- many-to-many
- many user lvl threads mapped to many kernel threads
locality of mapping is a concern
asynchronous threading
- parent spawns child thread
- parent resumes execution
- parent/child run concurrently and independently of one another
- share little data
synchronous threading
- parent spawns child and waits for child to terminate
- children exchance data with each other but none with parent
thread pools
- create a fix set of threads ahead of time
- select available thread within pool to serve the next request
- queue request if there are no free threads in the pool
- creation overhead reduced
thread cancellation
- using pthread_cancel()
- deferred cancellation: target thread periodically checks whether it should terminate in an orderly manner