A thread is a basic unit of CPU
A thread is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack.
A web browser might have one thread display images or text while another thread retrieves data from the network, for example. A word processor may have a thread for displaying graphics, another thread for responding to keystrokes from the user, and a third thread for performing spelling and grammar checking in the background.
Benefits of multithreading: 1. Responsiveness 2. Resource sharing 3. Economy
• multicore or multiprocessor • A system is parallel if it can perform more than one task simultaneously. • concurrent system supports more than one task by allowing all the tasks to make progress.
Programming Challenges: 1. Identifying tasks. This involves examining applications to find area that can be divided into separate, concurrent tasks. Ideally, tasks are independent of one another and thus can run in parallel on individual cores. 2. Balance. While identifying tasks that can run in parallel, programmers must also ensure that the tasks perform equal work of equal value. 3. Data splitting. Just as applications are divided into separate tasks, the data accessed and manipulated by the tasks must be divided to run on separate cores.
4. Data dependency. The data accessed by the tasks must be examined for dependencies between two or more tasks. When one task depends on data from another, programmers must ensure that the execution of the tasks is synchronized to accommodate the data dependency 5. Testing and debugging. When a program is running in parallel on multiple cores, many different execution paths are possible. Testing and debugging such concurrent programs is inherently more difficult than testing and debugging single-threaded applications.
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. • Task parallelism involves distributing not data but tasks (threads) across multiple computing cores. Each thread is performing a unique operation.
Multithreading Models: • There are two types of threads to be managed in a modern system: User threads and kernel threads. • User threads are supported above the kernel, without kernel support. These are threads that application programmers would put into their programs. • Kernel threads are supported within the kernel of the OS itself. All modern OS support kernel level threads, allowing the kernel to perform multiple simultaneous tasks and/or to service multiple kernel system calls simultaneously. • In a specific implementation, the user threads must be mapped to kernel threads, using one of the following strategies. a. Many-to-One Model b. One-to-One Model c. Many-to-Many Model
In computer programming, green threads are threads that are scheduled by a runtime library or virtual machine (VM) instead of natively by the underlying operating system.
a. Many-to-One Model
b. One-to-one model
c. Many-to-Many Model • The many-to-many model multiplexes any number of user threads onto an equal or smaller number of kernel threads, combining the best features of the one-to-one and many-to-one models. • Users have no restrictions on the number of threads created. • Blocking kernel system calls do not block the entire process. • Processes can be split across multiple processors. • Individual processes may be allocated variable numbers of kernel threads, depending on the number of CPUs present and other factors
Thread Libraries A thread library provides the programmer with an API for creating and managing threads. Three main thread libraries are in use today: POSIX Pthreads, Windows, and JAVA.
• asynchronous threading, Synchronous threading • Synchronous threading occurs when the parent thread creates one or more children and then must wait for all of its children to terminate before it resumes —the so-called forkjoin
• Pthreads refers to the POSIX standard (IEEE 1003. 1 c) defining an API for thread creation and synchronization • Thread pool(file-server) • Open. MP is a set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments
Thank You……. . !
- Slides: 19