Re: How to detect NPTL at compile time

Hui Huang <[email protected]>
Newsgroups gmane.comp.lib.phil
Message-ID <[email protected]>
Jakub Jelinek wrote:
> On Fri, Apr 04, 2003 at 02:51:51PM -0800, Wan-Teh Chang wrote:
> 
>>Red Hat Linux 9 ships with the NPTL.  Our code
>>contains workarounds for LinuxThreads, and I
>>want to disable the workarounds if we are compiling
>>against NPTL.  How do I detect whether the pthread
>>library is LinuxThreads or NPTL at compile time?
>>Can I use the glibc version number to determine
>>that (i.e., NPTL if glibc 2.3 or higher)?

RH-9 has both NPTL and LinuxThreads. Your program could run
with either library. You should detect library type and
disable LT workarounds at runtime, not compile time.

> 
> 
> No.
> 
> int isnptl (void)
> {
>   size_t n = confstr (_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
>   if (n > 0)
>     {
>       char *buf = alloca (n);
>       confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
>       if (strstr (buf, "NPTL"))
>         return 1;
>     }
>   return 0;
> }
> 

As pointed out by another email today, apparently confstr()
doesn't work correctly on RH-9. It always returns "NPTL 0.29"
even I'm running with LinuxThreads. Any workaround for that?

thanks,
-hui
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.