error trashed by threading code for some IO operations. #4089

Save errno (or WSAGetLastError() on win32) before calls to
stop_thread_safe() if we're interested in the value. stop_thread_safe()
makes calls (like dprintf()) that may overwrite the error value.