linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Graegert <graegerts@gmail.com>
To: Glynn Clements <glynn@gclements.plus.com>
Cc: Luiz Fernando Capitulino <lcapitulino@conectiva.com.br>,
	linux-c-programming@vger.kernel.org
Subject: Re: errno usage.
Date: Mon, 1 Aug 2005 11:46:52 +0200	[thread overview]
Message-ID: <6a00c8d50508010246197ddabc@mail.gmail.com> (raw)
In-Reply-To: <17134.184.280815.897955@cerise.gclements.plus.com>

On 8/1/05, Glynn Clements <glynn@gclements.plus.com> wrote:
> 
> Steve Graegert wrote:
> 
> > > > Is it a bad pratice? Is there a 'limit' for 'errno' usage?
> > >
> > > No; there's no reason you can't use errno for your own purposes.
> >
> > This is acceptable for most cases but is not recommended for
> > multithreaded applications since two or more threads may set the
> > globally defined errno variable to report errors, but its use may
> > result it nondeterministic behavior.
> 
> In GNU libc 2.x, errno is a macro which refers to a thread-specific
> location.

OK.  Thanks for the update.

> > When using errno in a multithreaded environment (which is not
> > explicitly recommended by POSIX but acceptable to retain
> > compatibility) ISO/IEC 9945:1-1996 defines that errno.h should be
> > included in every source file to make sure that every thread accesses
> > its own errno variable to check for errors.  This is crucial to create
> > libraries that conform to POSIX and are reentrant.
> 
> Just to clarify: if you read or set errno, you have to include
> <errno.h>; don't use "extern int errno" (which will work on some
> systems, but not with glibc).

Agree.  Lots of ancient SYSV code I have worked on a couple of months
ago caused a lot of headaches because of "extern int errno" statements
that turned out to cause even more confusion when used in
multithreaded environments.  Nice to read that glibc is properly
prepared.

Regards

        \Steve

      reply	other threads:[~2005-08-01  9:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-29 15:00 errno usage Luiz Fernando Capitulino
2005-07-30 12:56 ` Glynn Clements
2005-08-01  7:22   ` Steve Graegert
2005-08-01 11:00     ` Glynn Clements
2005-08-01  9:46       ` Steve Graegert [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a00c8d50508010246197ddabc@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=glynn@gclements.plus.com \
    --cc=lcapitulino@conectiva.com.br \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).