How errno Is Handled in Multi-Threaded Programs

ID Number: Q37633

5.10

OS/2

docerr

Summary:

The "Microsoft C for MS OS/2 and MS-DOS Operating Systems: Version 5.1

Update" manual does not explain how errno is handled in multi-threaded

programs. The following explains this information.

More Information:

In single-threaded programs, errno is a function returning an int, as

can be observed by looking at the header file errno.h in the default

include subdirectory. In the multi-thread case, errno is a function

returning a pointer representing an array (as usual). This array has

32 entries, one for each thread. OS/2 API routine calls are used to

manage the assignation of threads to entries in this array. For the

multi-thread libraries, errno is defined as follows:

#define errno *(__errno())

where __errno is

int far * far __errno( void );

so "errno = EDOMAIN;" becomes "*(__errno()) = EDOMAIN;".

You can determine the behavior at compile time because errno will be

defined in the multi-thread case, i.e., "#ifdef errno".