KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q37633: How errno Is Handled in Multi-Threaded Programs

Article: Q37633
Product(s): See article
Version(s): 5.10
Operating System(s): OS/2
Keyword(s): ENDUSER | docerr | mspl13_c
Last Modified: 16-NOV-1988

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.

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".

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.