<pthread.h> includes

Stefan Farfeleder stefanf at FreeBSD.org
Fri Aug 19 18:35:14 GMT 2005

[threads@ added]

On Sat, Aug 20, 2005 at 12:04:56AM +1000, Bruce Evans wrote:
> On Fri, 19 Aug 2005, Stefan Farfeleder wrote:
> >I think some of the headers included by <pthread.h> violate the POSIX
> >specification (I'm looking at SUSv3/POSIX 1003.1 2004) by making more
> >symbols visible than allowed.
> >
> ><sys/cdefs.h>		Ok
> ><sys/types.h>		Ok
> ><sys/_pthreadtypes.h>	Ok
> ><sys/time.h>		No? (POSIX allows <time.h> which is a subset)
Actually POSIX kind of requires the inclusion of <time.h> (and
<sched.h>).  At least all symbols must be visible.

> ><sys/signal.h>		No?
> ><limits.h>		No?
> ><sched.h>		Ok
> >
> >Is this correct?  Should it be fixed?
> All of these includes except <sys/cdefs.h> and <sys/pthreadtypes.h> are
> wrong IMO:
> <sys/cdefs.h>		needed, but can be obtained as a side effect
> 			of including almost any other header in the list.
> <sys/types.h>		only used to declare size_t.  We handle this better
> 			in many other headers.  The old draft of POSIX that
> 			I'm looking at doesn't say that <pthread.h> declares
> 			size_t, so it might be conformant to use __size_t
> 			in the prototypes.

Removed, size_t is obtained via <time.h>.

> <sys/_pthreadtypes.h>	Ok
> <sys/time.h>		only used to declare sigset_t and struct timespec.
> 			We have a whole header, <sys/_sigset.h>, to help
> 			declare sigset_t better (it only declares 
> 			__sigset_t),
> 			and use it in many other headers.  We have 2 headers,
> 			<sys/timespec.h> and <sys/_timespec.h>, just to
> 			declare struct timespec, and use them in many other
> 			headers.  Here we only need a forward declaration of
> 			struct timespec or maybe struct __timespec, modulo
> 			POSIX bugs.  It is a bug in POSIX that <time.h> is
> 			allowed.  The old draft of POSIX doesn't say that
> 			<pthread.h> declares sigset_t or struct timespec
> 			(just that it may declare the latter).  This is
> 			unlike what it says for other headers.  E.g., we
> 			use <sys/timespec.h> in <sys/select.h> to satisfy
> 			the POSIX mistake that a complete struct timespec
> 			must be declared there.

I've include <machine/_types.h> (for __uint32_t) and <sys/_sigset.h>
instead.  timespec is declared through <time.h>.

> <sys/signal.h>		Just namespace pollution.

We need MINSIGSTKSZ from <machine/signal.h> though.  The patch includes
that header instead and protects its usage with __XSI_VISIBLE.  I'm not
happy with this, maybe MINSIGSTKSZ should be moved somewhere else?

> <limits.h>		Just namespace pollution.

<machine/_limits.h> is included instead and __ULONG_MAX is used.

> <sched.h>		only used to declare struct sched_param and to
> 			satisfy a POSIX mistake.  A forward declaration
> 			would suffice.

Left because POSIX says so.

The patch for <pthread.h> is at 
http://people.freebsd.org/~stefanf/pthread.h.diff .

There are a few files that need <sys/types>, <limits.h>, etc symbols and
get them by <pthread.h> inclusion, the patch at
http://people.freebsd.org/~stefanf/pthread.h-2.diff fixes that.  It
should probably be committed anyway.


More information about the freebsd-threads mailing list