Threads 4
Threads 4
Threads
Barsha Mitra
BITS Pilani CSIS Dept., BITS Pilani, Hyderabad Campus
Hyderabad Campus
Motivation
Most modern applications are multithreaded
Process creation is heavy-weight while thread creation is light-weight
Increases efficiency
create new
process to
send request service request Child
Client Server
Server
create new
thread to service
send request request
Client Server Thread
Data parallelism – distributes subsets of the same data across multiple cores,
same operation on each subset
KERNEL SPACE
Synchronous signals
• illegal memory access, div. by 0
• delivered to the same process that performed the operation generating the signal
Asynchronous signals
• generated by an event external to a running process
• the running process receives the signal asynchronously
• Ctrl + C, timer expiration
BITS Pilani, Hyderabad Campus
Signal Handling
For single-threaded process, signal is delivered to process
Where should a signal be delivered for multi-threaded process?
How to deliver a signal depends on the type of signal generated
synchronous signals thread causing the signal and not to other
threads in the process
some asynchronous signals (<Ctrl + C>) to all threads
Most multithreaded versions of UNIX allow a thread to specify which
signals it will accept and which it will block
Asynchronous signal may be delivered only to those threads that are
not blocking it
default type
Deferred
Cancellation only occurs when thread reaches cancellation point
pthread_testcancel() creates a cancelation point within the calling
thread, so that a thread that is otherwise executing code that contains no
cancelation points will respond to a cancelation request
If cancellation request is pending, cleanup handler is invoked to release acquired
resources
BITS Pilani, Hyderabad Campus
Thank You