This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Reentrant functions & concurrency


I have a question on the implementation of the functions in
newlib/libc/reent, which are the reentrant versions of Unix system
calls.

Taking writer.c as an example, we find the following function:

_ssize_t
_DEFUN (_write_r, (ptr, fd, buf, cnt),
     struct _reent *ptr _AND
     int fd _AND 
     _CONST _PTR buf _AND
     size_t cnt)
{
  _ssize_t ret;

  errno = 0;
  if ((ret = (_ssize_t)_write (fd, buf, cnt)) == -1 && errno != 0)
    ptr->_errno = errno;
  return ret;
} 

Of particular interest are the three lines starting with "errno = 0;".

What prevents an operating system from performing a context switch
between the call to _write() and the following assignment of errno to
the reentrancy structure?  Such a context switch could cause errno to
change, which would result in an incorrect value of errno to be returned
to the application.

Shouldn't there be a _LOCK_T __errno_lock defined somewhere, a call to
__lock_acquire (__errno_lock) just before the line "errno = 0;" and a
call to __lock_release (__errno_lock) just before the line "return
ret;"?

Regards,

Konrad Schwarz


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]