Re: Best Practices For Thread-Safe errno
On Oct 8, 9:42 pm, Goran <goran.pu...@gmail.com> wrote:
On Oct 8, 1:10 am, Le Chaud Lapin <jaibudu...@gmail.com> wrote:
Also, are you saying that errno, on systems that have threading, isn't
thread safe? I would guess that isn't the case (it would create
__horrible__ situations pretty quickly). If that is so, why not just
imitating whatever errno implementation does? In fact, you could also
get away with some "free range" of errno? And finally, since we are in
C++, not C, newsgroup, what's wrong with using exceptions, e.g.
Yes, IIUC, just using exisitng errno will not be thread-safe just
because program is build with multi-threaded library. Or?
class crt_error : public std::exception
{
int _errno;
public:
crt_error(/*add, maybe, some context here*/) : _errno(errno) {}
const char* what() {/*try handling strerror here*/}
};
if (failed(crt_call(params)))
throw crt_error(/*maybe context*/);
The above is IMO way easier than anything with "plain C", because
cleanup operations that often follow the error might/will bork errno,
so care has to be taken (e.g. each cleanup block has to be wrapped by
a get/set errno sequence).
Cannot think of a reason other laziness - I would like the luxury of
ignoring the error and not have program terminate if it is ok to
ignore the error in some situations.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]