Re: Best Practices For Thread-Safe errno
Le Chaud Lapin wrote:
Like others, I am follwing the general model of letting functions
return true/false to indicate success/failure, then setting an error
to indicate exactly what happened in the case of failure.
For C code, that seems okay, but not for C++ code. There, I would rather
throw an exception. Even for C, I would rather return the errorcode
directly instead of returning a boolean. Anyhow...
I would like to know if there is an portable or semi-portable
equivalent of Microsoft's SetLastError():
http://msdn.microsoft.com/en-us/library/ms680627(VS.85).aspx
Certainly, if a system is multi-threaded, it is not difficult to have
per-thread reserved space to stash the last error. On systems that are
not multi-threaded, no harm would be done.
Actually, I would be surprised to find a non-historic system without a
thread-safe errno. Note that errno is not an int but evaluates to an lvalue
of type int. The important distinction is that it often is a macro that
resolves to *_errno() and _errno() being a function that returns a pointer
to a thread-local object.
As for a portable equivalent, I believe Boost.Thread has a thread-local
storage.
Uli
--
Sator Laser GmbH
Gesch??ftsf??hrer: Thorsten F??cking, Amtsgericht Hamburg HR B62 932
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]