Documente Academic
Documente Profesional
Documente Cultură
Threads
Dr. Barsha Mitra
BITS Pilani CSIS Dept., BITS Pilani, Hyderabad Campus
Hyderabad Campus
Motivation
Most modern applications are multithreaded
Threads run within application
Multiple tasks with the application can be implemented by separate threads
Update display
Fetch data
Spell checking
Answer a network request
Process creation is heavy-weight while thread creation is light-weight
Can simplify code, increase efficiency
Data parallelism – distributes subsets of the same data across multiple cores,
same operation on each subset
Many-to-One
One-to-One
Many-to-Many
JOINING 10 THREADS
Signals are used in UNIX systems to notify a process that a particular event has
occurred
The signal is delivered to a process
When delivered, signal handler is used to process signals
Synchronous and asynchronous signals
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
Most multithreaded versions of UNIX allow a thread to specify which signals it will
accept and which it will block
In some cases, an asynchronous signal may be delivered only to those threads that
are not blocking it
Signals need to be handled only once, a signal is delivered only to the first thread
found that is not blocking it
default type
If thread has cancellation disabled, cancellation remains pending until thread enables it
Default type is deferred
Cancellation only occurs when thread reaches cancellation point
Establish cancellation point by calling pthread_testcancel()
If cancellation request is pending, cleanup handler is invoked to release any
acquired resources
Thread-local storage (TLS) allows each thread to have its own copy
of data
Application runs an upcall handler on this new virtual processor, which saves the state of the blocking thread
and relinquishes the virtual processor on which the blocking thread is running
Upcall handler then schedules another thread that is eligible to run on an available virtual processor
When the event that the blocking thread was waiting for occurs, the kernel makes another upcall to the
thread library informing it that the previously blocked thread is now eligible to run
Upcall handler for this event requires a virtual processor, and kernel may allocate a new virtual processor or
preempt one of the user threads and run the upcall handler on its virtual processor
After marking the unblocked thread as eligible to run, the application schedules an eligible thread to run
on an available virtual processor BITS Pilani, Hyderabad Campus
Scheduler Activations
Source: Scheduler Activations: Effective Kernel Support for the User-Level Management of Parallelism, THOMAS E. ANDERSON, BRIAN N.
BERSHAD, EDWARD D. LAZOWSKA, and HENRY M. LEVY, 1992
Source: Scheduler Activations: Effective Kernel Support for the User-Level Management of Parallelism, THOMAS E. ANDERSON, BRIAN N.
BERSHAD, EDWARD D. LAZOWSKA, and HENRY M. LEVY, 1992
Source: Scheduler Activations: Effective Kernel Support for the User-Level Management of Parallelism, THOMAS E. ANDERSON, BRIAN N.
BERSHAD, EDWARD D. LAZOWSKA, and HENRY M. LEVY, 1992