Responsiveness: single-threaded application would be unresponsive to the user until the operation had completed.
Resource sharing: Processes can only share resources through techniques such as shared memory and message passing
Economy: Allocating memory and resources for process creation is costly
Scalability: The benefits of multithreading can be even greater in a multiprocessor architecture, where threads may be running in parallel on different processing cores
5 of 16
6 of 16
Programming challenges
Identifying tasks
Balance
Data splitting
Data dependency
Testing and debugging
7 of 16
Types of parallelism
Data parallelism focuses on distributing subsets of the same data across multiple computing cores and performing the same operation on each core. For example, summing the contents of an array of size
Task parallelism involves distributing not data but tasks (threads) across multiple computing cores.
8 of 16
User threads are supported above the kernel and are managed without kernel support, whereas kernel threads are supported and managed directly by the operating system
Ultimately, a relationship must exist between user threads and kernel threads.
9 of 16
10 of 16
11 of 16
12 of 16
Thread Libraries
Pthreads
Windows threads
Java threads
13 of 16
Implicit threading
Transfer the creation and management of threading from application developers to compilers and run-time libraries.
Thread pooling: The general idea behind a thread pool is to create a number of threads at process startup and place them into a pool, where they sit and wait for work. When a server receives a request, it awakens a thread from this pool—if one is available—and passes it the request for service. Once the thread completes its service, it returns to the pool and awaits more work. If the pool contains no available thread, the server waits until one becomes free.
14 of 16
Multi-threading issues
Signaling
Synchronous Vs asynchronous
Thread cancellation
Asynchronous cancellation. One thread immediately terminates the target thread.
Deferred cancellation. The target thread periodically checks whether it should terminate, allowing it an opportunity to terminate itself in an orderly fashion.
15 of 16
Thread local storage
Scheduler activations
A final issue to be considered with multithreaded programs concerns communication between the kernel and the thread library, which may be required by the many-to-many and two-level models
The kernel provides an application with a set of virtual processors (LWPs), and the application can schedule user threads onto an available virtual processor.