A thread is a single, sequential flow of control within a program. Within each thread, there is a single point of execution. Most traditional programs consist of a single thread. Figure 1-1 and Figure 1-2 show the differences between a single threaded process and a multithreaded process.
Using DECthreads, Digital's multithreading run-time library, a programmer can create several threads within a program. Threads execute concurrently, and, within a multithreaded program, there are at any time multiple points of execution. Threads execute within (and share) a single address space. Therefore, threads read and write the same memory locations. Synchronization elements such as mutexes and condition variables ensure that the shared memory is accessed correctly. DECthreads provides routines that allow you to create and use these synchronization elements. Mutexes and condition variables are discussed in Section 2.3.1 and Section 2.3.2.
In Figure 1-2, notice that multiple threads share heap storage, static storage, and code but that each thread has its own register set and stack.
DECthreads provides the following four separate application programming interfaces (APIs) with which you can perform multithreaded operations:
The pthread interface is an implementation of the IEEE Std 1003.1c-1995, POSIX Application Program Interface. More specifically, it is an extension to the 1003.1 Portable Operating System Interface (POSIX) standard rather than an independent interface specification. The DECthreads pthread implementation of the POSIX standard is the primary interface in the DECthreads environment. It is the most portable, efficient, and powerful interface in DECthreads.
The POSIX 1003.1c interfaces report errors by returning an integer value indicating the type of error.
The tis (thread independent services) is a Digital proprietary interface layered on top of the pthread interface. This API exists for building thread-safe code in nonthreaded applications. These routines provide their specified functionality when used in a program or application in which threads are present. In the absence of threads, these functions impose minimal overhead on the calling program. The tis objects created with these routines are DECthreads POSIX 1003.1c objects. You cannot create threads, since that has no meaning in a nonthreaded environment.
The cma interface is a Digital proprietary interface layered on top of the pthread interface. This interface to DECthreads will be obsolete in a future release in that it may no longer be enhanced or documented. The cma interface reports errors by raising exceptions. This interface is usually not available on non-Digital platforms and it is recommended that you migrate any cma code to the pthread interface to take advantage of new features and future enhancements.
This version of DECthreads retains full binary support and limited source support for the obsolete 1003.4a Draft 4 interfaces supported by earlier versions. This includes both the standard interface that reports errors by setting errno and returning a value of -1, and the exception returning interface that, like cma, reports errors by raising exceptions. The POSIX 1003.4a, Draft 4 interfaces will not be provided in future versions of DECthreads.
Appendix G provides detailed reference information on each DECthreads POSIX 1003.4a, Draft 4 (pthread) routine. These routines will be retired in a future release, but are provided for reference to assist code migration to the final POSIX standard interface. Do not try to use 1003.1c or POSIX 1003.4a Draft 4 routines on cma objects, or the reverse.