Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-04-05 03:04:10


On Mon, Apr 04, 2005 at 08:51:30PM -0400, Beman Dawes wrote:

>
> "Jonathan Wakely" <cow_at_[hidden]> wrote in message
> news:20050404134320.GA88664_at_compsoc.man.ac.uk...
>
> > Out of interest, why can't you just use _SC_THREAD_SAFE_FUNCTIONS if it's
> > defined?
> >
> > Also, if _POSIX_THREAD_SAFE_FUNCTIONS == 0, I thought that meant *not*
> > supported (in which case sysconf() would return -1) ? Does the test have
> > to be >= not just > ?
> >
> > I'd have written it:
> >
> > # if defined(_SC_THREAD_SAFE_FUNCTIONS)
> > if ( ::sysconf( _SC_THREAD_SAFE_FUNCTIONS ) > 0 )
> > { return ::readdir_r( dirp, entry, result ); }
> > # endif
> >
> > But I didn't realise this wasn't good enough :-|
>
> This is the first time I've ever used the POSIX config mechanisms, so I may
> have it wrong. I'll check... Hum... I find the POSIX docs for sysconf()
> pretty impeneratable regarding the return value. I can see why I took >=0 to
> be needed, but I could also read it in a way that >0 would be OK.

_POSIX_THREAD_SAFE_FUNCTIONS
    [TSF]
        The implementation supports the Thread-Safe Functions option. If
        this symbol is defined in <unistd.h>, it shall be defined to be
        -1, 0, or 200112L. The value of this symbol reported by
        sysconf() shall either be -1 or 200112L.

That's not to say that there aren't implementations that return 0, to
indiciate partial support (even though that's non-conforming.)

> Any POSIX experts out there?

My understanding is from Marc Rochkind's "Advanced UNIX Programming"
which is pretty thoroughly tested on Solaris, FreeBSD and Linux ... but
I'm never surprised to learn Tru64 does things differently.

> > Finally, readdir_r() is available on FreeBSD even though neither
> > _POSIX_THREAD_SAFE_FUNCTIONS not _SC_THREAD_SAFE_FUNCTIONS is defined.
> > I don't know how to test for it though, FreeBSD's sysconf() only claims
> > to support POSIX 1990, even though some later interfaces are available.
>
> Someone with access to that system needs to figure out what PP macro to look
> for.

I have access ... but I can't figure it out ;)

If _POSIX_SOURCE is not defined then the threadsafe functions are
declared (to keep the namespace clean when _POSIX_SOURCE *is* declared)

That's the case for FreeBSD 4.8 - 4.11, I don't know about anything
else. There doesn't seem to be a positive feature test for the
functions, only !defined(_POSIX_SOURCE)

jon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk