Just like the heap is implemented using a heap manager, and widestring management is left to a widestring manager, the threads have been implemented using a thread manager. This means that there is a record which has fields of procedural type for all possible functions used in the thread routines. The thread routines use these fields to do the actual work.
The thread routines install a system thread manager specific for each system. On Windows, the normal Windows routines are used to implement the functions in the thread manager. On Linux and other unices, the system thread manager does nothing: it will generate an error when thread routines are used. The rationale is that the routines for thread management are located in the C library. Implementing the system thread manager would make the RTL dependent on the C library, which is not desirable. To avoid dependency on the C library, the Thread Manager is implemented in a separate unit (cthreads). The initialization code of this unit sets the thread manager to a thread manager record which uses the C (pthreads) routines.
The thread manager record can be retrieved and set just as the record for the heap manager. The record looks (currently) as follows:
The meaning of most of these functions should be obvious from the descriptions in previous sections.
The InitManager and DoneManager are called when the threadmanager is set (InitManager), or when it is unset (DoneManager). They can be used to initialize the thread manager or to clean up when it is done. If either of them returns False, the operation fails.
There are some special entries in the record, linked to thread variable management:
The offset parameter indicates the offset in the thread variable block: All thread variables are located in a single block, one after the other. The size parameter indicates the size of the thread variable. This function will be called once for all thread variables in the program.
It should return the new location for the thread-local variable.