This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
RE: [pthreads-win32] How can you use errno with pthreads DLL?
- From: "Mark Weaver" <mark at npsl dot co dot uk>
- To: <pthreads-win32 at sources dot redhat dot com>
- Date: Wed, 19 Nov 2003 06:27:41 -0000
- Subject: RE: [pthreads-win32] How can you use errno with pthreads DLL?
>
> I am trying to use pthreads-win32 but have run into a problem. I get an
> error return value from pthreads-win32 but I can't use the errno because
> pthreads-win32 uses the errno for its C runtime library but my app uses
> its own errno from its C runtime library. How do I read the errno from
> pthreads-win32's view of things inside its DLL? I don't see a function
> for such a thing. I looked at the pthread.dsp file and it is set to use
> "Multithreaded DLL" library mode, so I figure that pthreads-win32 is
> more or less forcing me to use that mode. Well my application doesn't
> use that and can't do so.
>
> So is it not possible for there to simply be a pthreads-win32 function
> to get the errno? It may not be highly pretty but as it stands right now
> pthreads-win32 is unusable because of this problem.
>
Well it seems to me that you have a few options here:
1. Recompile pthreads against the same runtime library that you are using
rather than MSVC. This is more than likely the best solution as having two
different CRTs is nasty bloat: think two separate heaps and copies of all
support data structure, not to mention the additional code size.
2. Explicitly import and use the function "_errno" from MSVCRT.DLL. To
avoid the linker going nuts with two copies of most of the standard C
library symbols the least painful way to do this is to use LoadLibrary and
GetProcAddress. _errno basically is a wrapper around some thread local
storage: errno needs to be per thread in a multi-threaded environment.
TBH, I thought that pthreads didn't really use errno but opted to return an
errno.h defined status code. sem_* and sched_* do, so if you don't use
those you could bypass this problem.