Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 1999-07-24 23:06:27


> But I am sympathetic to the needs of programmers in threaded environments.
> I definitely agree that we should prohibit APIs that cannot be made thread safe
> --- errno, just say no.

Not that it is hard to make errno thread safe. Microsoft does it like this:

   #define errno (*_errno())

   int * __cdecl _errno(void) {
           return ( &(_getptd()->_terrno) );
   }

   _ptiddata __cdecl _getptd (void) {
           _ptiddata ptd;
           DWORD TL_LastError;

           TL_LastError = GetLastError();
           if ( (ptd = TlsGetValue(__tlsindex)) == NULL ) {
               /*
                * no per-thread data structure for this thread. try to create
                * one.
                */
               if ( ((ptd = _calloc_crt(1, sizeof(struct _tiddata))) != NULL) &&
                   TlsSetValue(__tlsindex, (LPVOID)ptd) ) {

                   /*
                    * Initialize of per-thread data
                    */

                   _initptd(ptd);

                   ptd->_tid = GetCurrentThreadId();
                   ptd->_thandle = (unsigned long)(-1L);
               } else
                   _amsg_exit(_RT_THREAD); /* write message and die */
               }

           SetLastError(TL_LastError);

           return(ptd);
   }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk