### Multithreaded Applications

A multithreaded application is one whose functions are divided among several threads. A process is an executing application and the resource it uses, a thread, is the smallest unit of execution within a process. Other than its stack and registers, a thread owns no resources; it uses those of its parent process.

In a single-thread program, all operations are performed serially; that is, one operation begins when the preceding one has finished. Multithread programs allow more complex processing.

There are two advantages to having multiple threads:

- On multiprocessor systems, threads can execute concurrently and the program completes execution faster.
- On single-processor or multiprocessor systems, if any thread is blocked (waiting for I/O to complete), the rest of the application can continue to process or respond to user data.

Although threads within a process share the same address space and files, each thread runs independently and is not affected by the control flow of any other thread in the process. Because a function from any thread can perform any task, such as input or output, threads are well suited to programs that have multiple uses of the same data or resources.

Multithread programming is a feature of the OS/2 and Windows operating systems and is supported by IBM C and C++ Compilers with compiler options, linker options, and multithread libraries.

Thread Local Storage

Create and Delete Threads (Windows)
Create and Delete Threads (OS/2)
Use the Multithread Libraries
Debugging Threads
Terminate Execution with Multiple Threads

Global and Common Variables
Using Common Variables
Rules and Restrictions on Using TLS
Reentrant Functions
Calls to Nonreentrant Functions
Signal and Exception Handling in Multithreaded Applications